note 68244 deleted from function.ereg by nlopess
| From: | nlopess@php.net | Date: | Wed, 19 Jul 2006 18:23:32 +0000 |
| Subject: | note 68244 deleted from function.ereg by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114941@lists.php.net to get a copy of this message | ||
Note Submitter: PHP-Expert
----
If you want to deal with a pattern that include special chars like '+' or '^' it
will not work proberly because they aren't masked. So I wrote a little function which exactly
does that for me:
<?php
function ofre($string) // OptimizeForRegularExpressions, you can name it what you want to
{
$string = str_replace("/", "\/", $string);
$string = str_replace(".", "\.", $string);
$string = str_replace("+", "\+", $string);
$string = str_replace("*", "\*", $string);
$string = str_replace("?", "\?", $string);
$string = str_replace("^", "\^", $string);
$string = str_replace("$", "\\$", $string);
$string = str_replace("|", "\|", $string);
$string = str_replace("(", "\(", $string);
$string = str_replace(")", "\)", $string);
$string = str_replace("[", "\[", $string);
$string = str_replace("]", "\]", $string);
$string = str_replace("{", "\{", $string);
$string = str_replace("}", "\}", $string);
return $string;
}
?>