Skip to content

Conversation

@EmmanuelVella
Copy link
Contributor

Geoip module return ISO-8859-1 encoded strings. Special characters are broken if they are not converted to utf8 before applying a transformation (like in https://github.com/willdurand/Geocoder/blob/master/src/Geocoder/Result/AbstractResult.php#L64)

You can try with this IP : 79.120.148.112 (Bogyoszló)

Geoip module return ISO-8859-1 encoded strings. Special characters are broken if not converted to utf8 before applying any transformation (like https://github.com/willdurand/Geocoder/blob/master/src/Geocoder/Result/AbstractResult.php#L64)
@toin0u
Copy link
Member

toin0u commented May 2, 2013

Good catch, we get Bogyoszl we should get Bogyoszló:

snip20130502_7

{"latitude":47.561199188232,"longitude":17.184400558472,"bounds":null,"streetNumber":null,"streetName":null,"zipcode":"","city":"Bogyoszl","cityDistrict":null,"county":null,"countyCode":null,"region":"Gyor-Moson-Sopron","regionCode":"09","country":"Hungary","countryCode":"HU","timezone":"Europe\/Budapest"}

Maybe it's better to fix the formatString method instead. @willdurand WDYT ?

@EmmanuelVella
Copy link
Contributor Author

I tried to replace the UTF-8 string in the formatString method by mb_detect_encoding($str) : unfortunately, the detection does not work as expected as it returns UTF-8 instead of ISO-8859-1 !

@EmmanuelVella
Copy link
Contributor Author

@toin0u
Copy link
Member

toin0u commented May 2, 2013

Did you tried the strict mode in mb_detect_encoding ?

Something like:

$str = mb_detect_encoding($str, 'UTF-8', true) ? $str : utf8_encode($str);

@EmmanuelVella
Copy link
Contributor Author

It only works with mb_detect_encoding($str, 'UTF-8, ISO-8859-1', true); ! (else it returns false)

@toin0u
Copy link
Member

toin0u commented May 2, 2013

Ok, so your solution is the best I guess 👍

@EmmanuelVella
Copy link
Contributor Author

If geoip is the only provider which returns non-utf8 strings, indeed the initial solution is maybe better !

@toin0u
Copy link
Member

toin0u commented May 2, 2013

I agree :)

willdurand added a commit that referenced this pull request May 3, 2013
Fix encoding for geoip provider
@willdurand willdurand merged commit 0bbe1a5 into geocoder-php:master May 3, 2013
@willdurand
Copy link
Member

thanks!

@EmmanuelVella EmmanuelVella deleted the patch-1 branch May 3, 2013 06:52
@Nelrann
Copy link

Nelrann commented May 3, 2013

yes! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants