Skip to content

Instantly share code, notes, and snippets.

@heiglandreas
Created November 30, 2016 18:27
Show Gist options
  • Save heiglandreas/4f8dc0c03794ae6413e157960d3c3544 to your computer and use it in GitHub Desktop.
Save heiglandreas/4f8dc0c03794ae6413e157960d3c3544 to your computer and use it in GitHub Desktop.
Compare Iconv and Intl for Transliteration
Heiz��lr��cksto��d��mpfer
Heizoelrueckstossdaempfer
<?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