stefangabos / world_countries

Constantly updated lists of world countries and their associated alpha-2, alpha-3 and numeric country codes as defined by the ISO 3166 standard, available in CSV, JSON , PHP, SQL and XML formats, in multiple languages and with national flags included; also available are the ISO 3166-2 codes of provinces/ states associated with the countries
http://stefangabos.github.io/world_countries/
Other
1.34k stars 374 forks source link

Typo in readme causing error #64

Closed KRens closed 2 years ago

KRens commented 2 years ago

In the readme.md there are a few error's causing error's in the code. search_county(array('id' => 250}); search_county(array('alpha2' => 'fr'}); search_county(array('alpha3' => 'fra'});

=> 1) This should be search_country instead of county! 2) This should be )); instead of }); 3) $countries = require 'path/to/countries.php'; does not work, you need just require 'path/to/countries.php'; This one already creates the $countries variable. 4) Your sample code does not seem to work with the _combined file.

The sample php code also does not work, I get following error: Fatal error: Uncaught TypeError: array_filter(): Argument #1 ($array) must be of type array, int given in C:\xampp\htdocs\account.php:214 Stack trace: #0 C:\xampp\htdocs\account.php(214): array_filter(1, Object(Closure)) #1 C:\xampp\htdocs\account.php(222): search_country(Array) #2 {main} thrown in C:\xampp\htdocs\account.php on line 214

I tried both loading the _combined as the language specific file, neither solves the issue. /vendor/stefangabos/world_countries/data/countries/en/countries.php

stefangabos commented 2 years ago

Thanks for the feedback! That code was built before the combined lists were available...I'll think of something but for now I'll leave it like that

stefangabos commented 2 years ago

...also the combined lists in PHP are broken, I am just noticing that now

KRens commented 2 years ago

Ok, point 1 to 3 are quick fixes for you, I got it working without the combined one for now.

Point 4: ok, clear, something for the future.

KRens commented 2 years ago

Your commit did not fix point number 3 ;-)

stefangabos commented 2 years ago

it works for me on PHP 7.3.19 what version are you using?

stefangabos commented 2 years ago

the PHP files that I have don't have a variable name in them and look like this

<?php return array(
    4   => array('id' => 4  , 'alpha2' => 'af', 'alpha3' => 'afg', 'name' => 'Afghanistan'),
    8   => array('id' => 8  , 'alpha2' => 'al', 'alpha3' => 'alb', 'name' => 'Albania'),
stefangabos commented 2 years ago

i fixed the combined lists in PHP - as in, they now work instead of being broken. the function in the readme.md still doesn't apply for the combined data

stefangabos commented 2 years ago

I added a note in the README.md highlighting the fact that the functions work for the non-combined data sets

stefangabos commented 2 years ago

thanks for your feedback!

KRens commented 2 years ago

$countries = require 'path/to/countries.php'; doesn't work for me. require 'path/to/countries.php'; does

This since the php file file already contains "$countries = array(" and puts it in the correct variable.

I'm using PHP 7.4.26

stefangabos commented 2 years ago

the php file does not contain $countries = array( you must be using an older version

stefangabos commented 2 years ago

ah, i see now - i don't yet have a release with the updates done to the PHP files - my bad

stefangabos commented 2 years ago

this is a change suggested in #58 and which has been already implemented

stefangabos commented 2 years ago

i just published a new release and it is now available via npm and packagist