Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

strtr versus str replace

which have you found to be faster?



12:57 pm on Jun 21, 2009 (gmt 0)

5+ Year Member

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!


12:38 pm on Jun 22, 2009 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

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.

Featured Threads

Hot Threads This Week

Hot Threads This Month