1

I'd like to use the normalizer class to achieve something like:

'ö ä ü é ô' => 'o a u e o'

I ran this php-script:

header("Content-Type: text/html; charset=UTF-8");
echo Normalizer::normalize('ö ä ü é ô', Normalizer::FORM_C);

the result is:

ö ä ü é ô

So there is no difference to the input. What can I do?

AndiPower
  • 853
  • 10
  • 20
  • 1
    That's not what the normalizer does, your expectations are wrong. There are many other questions for how to "remove diacritics from characters", look at those. – deceze Sep 14 '13 at 12:52
  • Ok, this is where my expectaions came from: http://stackoverflow.com/questions/6284118/convert-national-chars-into-their-latin-equivalents-in-php – AndiPower Sep 14 '13 at 12:57
  • 1
    Wow, that's just... wrong. – deceze Sep 14 '13 at 13:02

2 Answers2

2

There really isn't a direct way to do this, but with iconv you can change the charset of the string to another charset that doesn't have those accents, and if you use //TRANSLIT it will instead use the closest approximation.

You can find several examples in the User Contributed Notes at: http://us2.php.net/manual/en/function.iconv.php.

E: you can also do this with the Normalizer class:

<?php
header("Content-Type: text/html; charset=UTF-8");
$text = "ö ü ä";
echo preg_replace('/\pM*/u','',normalizer_normalize( $text, Normalizer::FORM_D));
Yoshi-
  • 71
  • 2
2

Instead of Normalizer you should use Transliterator

$str = 'ö ä ü é ô';
echo Transliterator::create('Latin-ASCII')->transliterate($str);
dev-null-dweller
  • 29,274
  • 3
  • 65
  • 85