note 68244 added to function.ereg

From: Date: Wed, 19 Jul 2006 15:41:26 +0000
Subject: note 68244 added to function.ereg
Groups: php.notes 
Request: Send a blank email to php-notes+get-114932@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 212.124.37.9 Probable Submitter: 87.123.31.22 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.ereg.php Edit -- http://master.php.net/note/edit/68244 Del: integrated -- http://master.php.net/note/delete/68244/integrated Del: useless -- http://master.php.net/note/delete/68244/useless Del: bad code -- http://master.php.net/note/delete/68244/bad+code Del: spam -- http://master.php.net/note/delete/68244/spam Del: non-english -- http://master.php.net/note/delete/68244/non-english Del: in docs -- http://master.php.net/note/delete/68244/in+docs Del: other reasons-- http://master.php.net/note/delete/68244 Reject -- http://master.php.net/note/reject/68244 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114932) next »