Welcome to WebmasterWorld Guest from 184.108.40.206 , register , free tools , login , search , pro membership , help , library , announcements , recent posts , open posts Become a Pro Member
strtr versus str replace which have you found to be faster? lethal0r
in working on optimizing my website I have read many posts on these 2 functions, and it seems to be split down the middle as to which is faster.
in my case I found that if you need to check for many replacements in one go, then strtr is faster. for example I am doing this kind of thing
$text = strtr($text, array('é' => 'e', 'È' => 'E', 'Â' => 'A'));
plus another 20 replacements or so. I tested both functions 10 times each and strtr was faster 8 times.
I would be interested to hear any one elses experiences here!
I've never measured one against the other for speed/performance but you may also add a regular expression to your tests to see how that performs too. The regular expression engine in the latest PHP5 releases has been quite impressive.