Welcome to WebmasterWorld Guest from 54.196.208.6

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)

Full Member

10+ Year Member

joined:Dec 8, 2005
posts: 231
votes: 0


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 June 22, 2009 (gmt 0)

Administrator

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

joined:July 31, 2003
posts:12533
votes: 0


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.