note 71469 deleted from function.preg-match by colder

From: Date: Mon, 18 Jun 2007 18:33:54 +0000
Subject: note 71469 deleted from function.preg-match by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127637@lists.php.net to get a copy of this message
Note Submitter: Elwin van Huissteden ---- Searching for a way to figure out how to make patterns in the preg_match command, I tried figuring out any piece of the patterns of others, and came to some conclusions... to try something out, i tried to make a pattern that could read if a backslash ( \ ) was used before a single quote ( ' ). I ended up with a pattern that read if any quotes where there at all, in any way possible. Maybe people could also use this, but if you see what i did wrong, please do tell me: <?php $string1 = "a \'quoted\' \"string\""; $string2 = "a 'quoted' string"; $string3 = "a &#039;quoted&#039; &quot;string&quot;"; $string4 = "a not-quoted string"; if (preg_match("/[\\'!']|[\\\"!\"]/",$string1)) { echo $string1.' wrong way'."\n"; } else { echo $string1.' right way'."\n"; } // returns: a \'quoted\' "string" wrong way if (preg_match("/[\\'!']|[\\\"!\"]/",$string2)) { echo $string2.' wrong way'."\n"; } else { echo $string2.' right way'."\n"; } // returns: a 'quoted' string wrong way if (preg_match("/[\\'!']|[\\\"!\"]/",$string3)) { echo $string3.' wrong way'."\n"; } else { echo $string3.' right way'."\n"; } // returns: a 'quoted' "string" right way if (preg_match("/[\\'!']|[\\\"!\"]/",html_entity_decode($string3))) { echo html_entity_decode($string3).' wrong way'."\n"; } else { echo html_entity_decode($string3).' right way'."\n"; } // returns: a 'quoted' "string" wrong way if (preg_match("/[\\'!']|[\\\"!\"]/",$string4)) { echo $string4.' wrong way'."\n"; } else { echo $string4.' right way'."\n"; } // returns: a not-quoted string right way ?>

« previous php.notes (#127637) next »