note 57108 added to function.preg-match

From: Date: Fri, 23 Sep 2005 21:56:34 +0000
Subject: note 57108 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-95673@lists.php.net to get a copy of this message
/** 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; } ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57108 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57108&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57108&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57108&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57108&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57108&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57108&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57108&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57108&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95673) next »