- utf8_decode: documentation ( source)
- microtime: documentation ( source)
- strtr: documentation ( source)
- utf8_encode: documentation ( source)
<?php
$string='sadfsakfjbsadjkfhsadkjfhasdlkjhfksahjksdhfkjasdhflkjashfkjshadkfjhsakldfjhsakf';
$time=microtime(true);
for($i=0;$i<1000;$i++)
removeaccents1($string);
$time=microtime(true)-$time;
echo "New took $time seconds\n";
$time=microtime(true);
for($i=0;$i<1000;$i++)
removeaccents2($string);
$time=microtime(true)-$time;
echo "Old took $time seconds\n";
function removeaccents1($string)
{
return utf8_encode(strtr(utf8_decode($string),utf8_decode('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'),'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy'));
}
function removeaccents2($string)
{
return strtr($string,'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ','SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy');
}