note 46388 added to function.preg-match
| From: | j dot gizmo at aon dot at | Date: | Sat, 09 Oct 2004 13:00:29 +0000 |
| Subject: | note 46388 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78220@lists.php.net to get a copy of this message | ||
in reply to rchoudhury --} pinkgreetings {-- com....
the code pasted below (with the switch statement) CANNOT work.
the construct works like this
<?php
switch ($key)
{
case <expr>:
//this will be executed if $key==<expr>, where <expr> can be a literal, function call
etc.
echo "1";
break;
}
//the following will work
switch (true)
{
case preg_match("/pattern/",$key):
//if $key matches pattern, preg_match will return true, and this case will be executed (true==true)
blablablabla();
break;
}
?>
however, it makes no sense to compare $key to the return value of preg_match(), and calling
preg_match without a second parameter is utterly senseless as well (PHP can't smell what you
want to compare pattern to)
the syntax error in your regular expression is the double slash in the beginning.
(RTFM)
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46388
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46388&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46388&report=yes
Search -- http://master.php.net/manage/user-notes.php