Created
November 30, 2016 18:27
-
-
Save heiglandreas/4f8dc0c03794ae6413e157960d3c3544 to your computer and use it in GitHub Desktop.
Compare Iconv and Intl for Transliteration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Heiz��lr��cksto��d��mpfer | |
Heizoelrueckstossdaempfer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo Uconverter::transcode('Heizölrückstoßdämpfer', 'UTF-8', 'ASCII'); | |
echo "\n\n"; | |
setlocale(LC_CTYPE, 'de_DE.UTF-8'); | |
$iconvResult = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', 'Heizölrückstoßdämpfer'); | |
// This line is required as MacOS uses a different iconv-implementation | |
// that converts 'ä' to '"a' instead of 'ae'… | |
if (false !== strpos(php_uname('s'), 'Darwin')) { | |
$iconvResult = preg_replace("|\"(.)|", "$1e", $iconvResult); | |
} | |
echo $iconvResult; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment