preg_replace() is a builtin PHP function. It just happens to be an interface into a builtin copy of the perl regular expression engine. According to the intro to the PCRE (perl-compatible regular expression) section of the manual (
the PCRE functions require no external libraries and have been turned on by default since PHP version 4.2.0. And of the two regular expression systems supported by PHP, the PCRE family of functions are recommended by the online manual.
That's about as pure a PHP solution as you're going to get. And when you're talking regular expressions, there may not necessarily be a simple solution.
To be honest, I gave you the less-than-optimal solution. If you want to do a simple non-regular-expression string replacement (which your question is), then the PHP online manual recommends not using regular expressions. The better version of the code would be:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.