note 57108 deleted from function.preg-match by jome

From: Date: Fri, 30 Sep 2005 18:56:50 +0000
Subject: note 57108 deleted from function.preg-match by jome
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96079@lists.php.net to get a copy of this message
Note Submitter: mark dot meves at google's free email ---- /** escape any string for use inside a regular expression such that special characters are used literally. @return the new string note that if you use a non-standard regex delimiter (usu. "|" or "/") add that to the list. kevin dot bro may have a "better" version below (march '03) */ function preg_escape($sUnescaped) { $sCharsThatHaveSpecialMeaningInRegexes = '/\\^$.[]|()?*+{}'; $sSpecialCharsEscaped = implode('\\', str_split($sCharsThatHaveSpecialMeaningInRegexes) ); $sOccurencesOfSpecialCharsPrecededByBackslash = preg_replace( '|(['.$sSpecialCharsEscaped.'])|', '\\\${1}', $sUnescaped ); return $sOccurencesOfSpecialCharsPrecededByBackslash; }

« previous php.notes (#96079) next »