Which of the following functions is most efficient for substituting fixed patterns in strings?
Top Questions
A. preg_replace()
B. str_replace()
C. str_ireplace()
D. substr_replace()
Answer B is correct.
The PHP efficiency mantra is “do no more work than necessary.”
Both str_ireplace() and preg_replace() have more expensive (and flexible)
matching logic, so you should only use them when your problem requires it.
substr_replace() requires you to know the offsets and lengths of the substrings
you want to replace, and is not sufficient to handle the task at hand.
Post new comment