5

I am working on a little website for my mother in php, using mysql. I want to use the inserted cities to spit out Google Maps.

Problem is that if you insert a city with a Swedish name, such as Norrköping, Google won't give you a map. You have to insert "Norrkoping" without the umlauts.

Is there a way I can change the charset with getting the info, or inputting it, so the dots are removed?

Same thing får Åå (store as Aa) and Ää (store as Aa).

Thanks!

Stephanie
  • 53
  • 2
  • 1
    i was just able to search `Norrköping` on google maps and it worked fine – Naftali Mar 28 '11 at 16:25
  • A quick SO search turned this up: [http://stackoverflow.com/questions/158241/php-replace-umlauts-with-closest-7-bit-ascii-equivalent-in-an-utf-8-string](http://stackoverflow.com/questions/158241/php-replace-umlauts-with-closest-7-bit-ascii-equivalent-in-an-utf-8-string) – Wesley Murch Mar 28 '11 at 16:25
  • 1
    possible duplicate of [Remove accents without using iconv](http://stackoverflow.com/questions/3542818/remove-accents-without-using-iconv) – Jon Mar 28 '11 at 16:25

3 Answers3

3

Use the iconv method.

echo iconv("utf-8","ascii//TRANSLIT","Norrköping");
Mike Lewis
  • 63,433
  • 20
  • 141
  • 111
0

Why not something like this?

$s = array('Å', 'å', 'Ö', 'ö');
$r = array('A', 'a', 'O', 'o');
$name = str_replace($s, $r, $name);

Translating "svensk-o" to "a" is not really all that much correct, I guess... but it's what you need to make it work, right? You would of course need to add a few more characters if Nürnberg or Crécy are supposed to be un-accented too, but the number of umlauts is very limited, luckily... :-)

Damon
  • 67,688
  • 20
  • 135
  • 185
0
$string = iconv(mb_detect_encoding($string), "ASCII//TRANSLIT", $string);
echo $string;
Dejan Marjanović
  • 19,244
  • 7
  • 52
  • 66