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 'quoted'
"string"";
$string4 = "a not-quoted string";
if
(preg_match("/[\'!']|[\"!"]/",$strin
g1)) {
echo $string1.' wrong way'."n";
} else {
echo $string1.' right way'."n";
}
// returns: a 'quoted' "string" wrong way
if
(preg_match("/[\'!']|[\"!"]/",$strin
g2)) {
echo $string2.' wrong way'."n";
} else {
echo $string2.' right way'."n";
}
// returns: a 'quoted' string wrong way
if
(preg_match("/[\'!']|[\"!"]/",$strin
g3)) {
echo $string3.' wrong way'."n";
} else {
echo $string3.' right way'."n";
}
// returns: a 'quoted' "string" right way
if
(preg_match("/[\'!']|[\"!"]/",html_e
ntity_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("/[\'!']|[\"!"]/",$strin
g4)) {
echo $string4.' wrong way'."n";
} else {
echo $string4.' right way'."n";
}
// returns: a not-quoted string right way
?>
----
Server IP: 83.137.20.120
Probable Submitter: 82.92.27.234
----
Manual Page --
http://www.php.net/manual/en/function.preg-match.php
Edit -- https://master
.php.net/note/edit/71469
Del: integrated -- h
ttps://master.php.net/note/delete/71469/integrated
Del: useless -- http
s://master.php.net/note/delete/71469/useless
Del: bad code -- htt
ps://master.php.net/note/delete/71469/bad+code
Del: spam -- https:/
/master.php.net/note/delete/71469/spam
Del: non-english --
https://master.php.net/note/delete/71469/non-english
Del: in docs -- http
s://master.php.net/note/delete/71469/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/71469
Reject -- https://mast
er.php.net/note/reject/71469
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|