RE: [PHP] Re: elseifs and ereg

From: Date: Sat, 05 Oct 2002 00:10:00 +0000
Subject: RE: [PHP] Re: elseifs and ereg
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-118919@lists.php.net to get a copy of this message
> 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-0000]", $now)) > $out = "night"; > elseif (ereg("[0001-0559]", $now)) > $out = "too late"; > else > $out = "no matches";

« previous php.general (#118919) next »