I have a script where 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()?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.