homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

strtr versus str replace
which have you found to be faster?

5+ Year Member

Msg#: 3937687 posted 12:57 pm on Jun 21, 2009 (gmt 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!



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

Msg#: 3937687 posted 12:38 pm on Jun 22, 2009 (gmt 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved