|
Posted by Janwillem Borleffs on 03/11/06 14:48
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.
JW
Navigation:
[Reply to this message]
|