Re: Preg Match Problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2 Jun 2010 12:14:47 -0400
Alice Wei <ajwei@xxxxxxxxxxxxx> wrote:

> 
> Hi, 
> 
> I have a code snippet here as in the following:
> 
> [CODE]
> $keywords = preg_split("/[\s,]+/", $day);
> $count = count($keywords);
>   if(preg_match("(Mon|Tue|Wed|Thu|Fri)/i", $keywords[$i])) { //line 40
>    $day_query ="start_time.day='12345' AND end_time.day='12345'";  
>    }  
>    if(preg_match("Sat/i", $keywords[$i])) { //line 43
>    $day_query = "start_time.Sat_route != 'NULL' AND end_time.Sat_route != 'NULL'";
>    }  
>    else {
>    echo $keywords[i] . " is not a term that exists in the database. Make sure the pattern looks like <b>Mon, Tue</b><br />";
>    footer();
>    exit;
>    }
> [/CODE]
> 
> For some reason, when I type in Mon, Tue
> 
> It gives me this: 
> 
> Warning: preg_match() [function.preg-match]: Unknown modifier '/' in line 40
> Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash on line 43
> is not a term that exists in the database. Make sure the pattern looks like Mon, Tue

You need a leading slash as a delimiter, eg
"/Sat/i"
also note that you will match any phrase that contains 'sun', 'mon' etc, which can also have irrelevant text, eg 'Mars Jupiter Saturn' will match, but thats probably not what you want
-- 
Simcha Younger <simcha@xxxxxxxxxxxx>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux