Re: How to put these 2 IF statements into 1, with regex?
| From: | CC Zona | Date: | Mon, 01 Jul 2002 02:16:18 +0000 |
| Subject: | Re: How to put these 2 IF statements into 1, with regex? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-104611@lists.php.net to get a copy of this message | ||
In article <200207010129.g611TIu21790@www.drsbps.net>, php@net.co.cr
wrote:
> I was wondering if there is anyway to combine these two IF statements
> into one:
>
> if (preg_match("@siteUserList.cgi?group=site177@", $QUERY_STRING))
>
> and:
>
> if (preg_match("@siteUserList.cgi?group=site177&@", $QUERY_STRING))
Remember that preg_* functions aren't equivalent to str_*; you're matching
against a regex pattern now, not just a simple text string. So you must
first escape any regex special characters within your text string if you
want reliable results. Otherwise, you're going to eventually end up with
unintended matches like "siteUserList9cggroup=site177&".
Regarding the rest of your question: the "?" character is what you seek.
if (preg_match("/siteUserList\.cgi\?group=site177&?/", $QUERY_STRING))
--
CC