From: Alice Wei on

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

Have I done something wrong here?
Thanks for your help.

_________________________________________________________________
Hotmail is redefining busy with tools for the New Busy. Get more from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2
From: Peter Lind on
On 2 June 2010 18:14, Alice Wei <ajwei(a)alumni.iu.edu> 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

You're lacking the starting delimiter '/'

Regards
Peter

--
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>
From: Alice Wei on


> From: peter.e.lind(a)gmail.com
> Date: Wed, 2 Jun 2010 18:17:00 +0200
> Subject: Re: [PHP] Preg Match Problem
> To: ajwei(a)alumni.iu.edu
> CC: php-general(a)lists.php.net
>
> On 2 June 2010 18:14, Alice Wei <ajwei(a)alumni.iu.edu> 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
>
> You're lacking the starting delimiter '/'
>
> Regards
> Peter
>

Thanks, that did the trick.

Alice

> --
> <hype>
> WWW: http://plphp.dk / http://plind.dk
> LinkedIn: http://www.linkedin.com/in/plind
> BeWelcome/Couchsurfing: Fake51
> Twitter: http://twitter.com/kafe15
> </hype>

_________________________________________________________________
The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4
From: Simcha Younger on
On Wed, 2 Jun 2010 12:14:47 -0400
Alice Wei <ajwei(a)alumni.iu.edu> 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(a)syounger.com>