Re: str_ireplace() for php4?



Janwillem Borleffs wrote:

Simon wrote:
Just out of curiosity, would it work if $needle, $str, $haystack had
escape/special characters?

Good point. You need to escape reserved regular expression characters in
$needle as follows:

if (!function_exists('str_ireplace')) {
function str_ireplace($needle, $str, $haystack) {
$needle = preg_quote($needle, '/');
return preg_replace("/$needle/i", $str, $haystack);
}
}

$str and $haystack do not need to be modified.

What if $str contained "\1"?

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

.



Relevant Pages

  • Re: str_ireplace() for php4?
    ... You need to escape reserved regular expression characters in ... $str and $haystack do not need to be modified. ...
    (comp.lang.php)
  • Re: str_ireplace() for php4?
    ... for php4? ... my head around it. ... function str_ireplace($needle, $str, $haystack) { ...
    (comp.lang.php)
  • Re: str_ireplace() for php4?
    ... for php4? ... my head around it. ... function str_ireplace($needle, $str, $haystack) { ...
    (comp.lang.php)