note 34083 deleted from function.preg-quote by felipe

From: Date: Mon, 10 Dec 2007 02:21:02 +0000
Subject: note 34083 deleted from function.preg-quote by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133103@lists.php.net to get a copy of this message
Note Submitter: adrian holovaty ---- 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);

« previous php.notes (#133103) next »