-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code 'EUR' not found #1
Comments
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); |
The same problem. Don't affect the result. |
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. $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 |
@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. |
Description
I have code:
$code = 'EUR';
$cnb = new \CnbApi\CnbApi(storage_path('app/cnb'));
$a = $cnb->findRateByCode($code);
print_r($a);
exit;
When I run it, it shows error: Code 'EUR' not found
Where can be problem?
The text was updated successfully, but these errors were encountered: