开发者

Which function is faster? substr() or str_replace()? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜