RE: [PHP] Re: elseifs and ereg
> Err, yeah, I just figured that out. So now I have this, but it always > matches the first. I even tried setting $now = "2221" > > Thanks for the help! > > Bryan > > > $now = date("Hi", strtotime("now")); > $out = "not set"; Hey...you've got that right now...kind of. > if (ereg("[2200-2230]", $now)) > $out = "special"; Go back to the manual, please. Your ereg string is only matching (or looking to match) one character. You are looking for a single character in your string that is a 2 or 2 or 0 to 2 or 2 or 3 or 0. That'll match "2221" every time... Why are you using ereg when a less than / greater than will work faster and easier? ---John Holmes... > elseif (ereg("[0600-1159]", $now)) > $out = "morning"; > elseif (ereg("[1200-1659]", $now)) > $out = "afternoon"; > elseif (ereg("[1700-1959]", $now)) > $out = "evening"; > elseif (ereg("[2000-]", $now)) > $out = "night"; > elseif (ereg("[0001-0559]", $now)) > $out = "too late"; > else > $out = "no matches"; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: elseifs and ereg
Err, yeah, I just figured that out. So now I have this, but it always matches the first. I even tried setting $now = "2221" Thanks for the help! Bryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: elseifs and ereg
check the manual page for ereg... you'll find that it takes 2 parameters minimum, and the return value is not what your code expects it to be. http://www.php.net/ereg "Bryan Koschmann - Gkt" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Okay, I think I'm just being stupid here. Can someone please tell me why > this is wrong? Yeah I know it looks lame, but I'm just testing something. > > This always returns "no matches" > > Thanks, > > Bryan > > > $now = strtotime("now"); > $out = "never set"; > if ($now == ereg("[2200-2230]")) > $out = "special"; > elseif ($now == ereg("[0600-1159]")) > $out = "morning"; > elseif ($now == ereg("[1200-1659]")) > $out = "afternoon"; > elseif ($now == ereg("[1700-1959]")) > $out = "evening"; > elseif ($now == ereg("[2000-]")) > $out = "night"; > elseif ($now == ereg("[0001-0559]")) > $out = "too late"; > else > $out = "no matches"; > > print(date("Hi", $now)); > print "\n$out\n"; > > > ?> > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php