note 34083 added to function.preg-quote

From: Date: Tue, 15 Jul 2003 22:12:15 +0000
Subject: note 34083 added to function.preg-quote
Groups: php.notes 
Request: Send a blank email to php-notes+get-52154@lists.php.net to get a copy of this message
Note that if you've used the "x" pattern modifier in your regex, you'll want to make sure you escape any whitespace in your string that you *want* the pattern to match. A simplistic example: $phrase = 'a test'; // note the space $textbody = 'this is a test'; // Does not match: preg_match('/' . preg_quote($phrase) . '$/x', $textbody); function preg_quote_white($a) { $a = preg_quote($a); $a = str_replace(' ', '\ ', $a); return $a; } // Does match: preg_match('/' . preg_quote_white($phrase) . '$/x', $textbody); ---- Manual Page -- http://www.php.net/manual/en/function.preg-quote.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34083 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34083&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34083&report=yes

« previous php.notes (#52154) next »