Which function is faster? substr() or str_replace()? [closed]
I have a script where开发者_StackOverflow中文版 I can use either substr()
or str_replace()
. With substr()
I just have to cut off the last character and with str_replace I need to replace !
with nothing. Which one would be faster?
I guess substr()
?
I'm not familiar with the PHP source code, but I assume definitely substr()
, as it can jump directly to the defined offset.
Don't forget though that this will make a difference only with lots of data. For smaller strings, it is preferable to choose whatever makes for more readable code.
精彩评论