Giter VIP home page Giter VIP logo

Comments (4)

filipsedivy avatar filipsedivy commented on August 19, 2024 2

@TomasHalasz Thank you for reporting as soon as I get Windows and XAMPP, so I'll try and fix it immediately.

Please wait until the end of this weekend.

from cnb-api.

TomasHalasz avatar TomasHalasz commented on August 19, 2024 1

I have the same error. And I found reason. It depends on OS type. In Linux/OSX is everything OK, but on Windows with XAMPP I got error. So in cnb-api/Cnb.php at line 33 is CSV file exploded to array by PHP_EOL:

    public function getEntity(): ExchangeRate
    {
        $lines = explode(PHP_EOL, $this->content);

and there it is, because PHP_EOL gives (for me) wrong string in Windows OS.
I found on internet function for detecting used EOL, made some changes and solution is here:

$eol = $this->detectEol($this->content);
$lines = explode($eol, $this->content);

and function detectEol() is here:

/**Detects the end-of-line character of a string.
@param string $str      The string to check.
@return string The detected EOL, or default one.
 */
private static function detectEOL($str) {
	static $eols = array(
		'EOL_ACORN'   => "\n\r",  // 0x0A - 0x0D - acorn BBC
		'EOL_WINDOWS' => "\r\n",  // 0x0D - 0x0A - Windows, DOS OS/2
		'EOL_UNIX'    => "\n",    // 0x0A -      - Unix, OSX
		'EOL_TRS80'   => "\r",    // 0x0D -      - Apple ][, TRS80
	);
	$curCount = 0;
	$curEol = '';
	foreach($eols as $eol) {
		if( ($count = substr_count($str, $eol)) > $curCount) {
			$curCount = $count;
			$curEol = $eol;
		}
	}
	return $curEol;
}  // detectEOL

from cnb-api.

filipsedivy avatar filipsedivy commented on August 19, 2024

When I tried to reproduce the code, everything worked.

When you run this code, does it work?

$code = 'EUR';
$cnb = new \CnbApi\CnbApi();
$a = $cnb->findRateByCode($code);
print_r($a);

from cnb-api.

webdeal avatar webdeal commented on August 19, 2024

The same problem. Don't affect the result.

from cnb-api.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.