Re: Problem: ereg doesn't work ok (?).

From: Date: Thu, 20 Sep 2001 08:58:23 +0000
Subject: Re: Problem: ereg doesn't work ok (?).
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-67958@lists.php.net to get a copy of this message
<Original message> From: Lic. Rodolfo Gonzalez Gonzalez <rodolfo@equinoxe.g-networks.net> Date: Tue, Sep 18, 2001 at 08:15:50PM -0500 Message-ID: <Pine.LNX.4.33.0109181959320.7962-100000@equinoxe.g-networks.net> Subject: Re: [PHP] Problem: ereg doesn't wo > On Tue, 18 Sep 2001, * R&zE: wrote: > > > > and get DD-MM-YYYY, but with well formed YYYY-MM-DD it doesn't match!. Is > > > this a bug?. > > It would help if you send the code you're using, 'cause we can't see > > what you're doing now. FAFAIK it should just be possible. See the > > Sure: > > --- start --- > > $datenews = urldecode($datenews); // just in case, but it's the same > // without this line and the one below. > $datenews = trim($datenews); > > if (!ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $datenews, $regs)) { > echo "Duh! that is not a date, u kiddie: $datenews."; > exit; > } > else echo "Cool! it is a date. Continue the proggie."; > > --- end --- > > where $datenews is passed as a get variable, which is obtained with this: > > --- start --- > > // the $regs array comes from the ereg expression above (the one which > // doesn't work as expected). > > $timestamp = mktime(0,0,0,$regs[2],$regs[3],$regs[1]); > $yesterday = $timestamp - 86400; // one day before... that's yesterday :) > $yesternews = date("Y-m-d",$yesterday); > > // here I pass the new datenews to myself: > > print "<a > href=\"$PHP_SELF?datenews=".urlencode($yesternews)."\">Older > news</a>\n"; > > --- end --- > > This sometimes work, but sometimes it doesn't randomly, even with the same > date both times, and the worst thing is that the "failure notice" prints > the right date in the right format. Now I went back to php-4.0.6 > (apache-1.3.20, rh-7.1) and it's the same. Any help is appreciated. Thank > you. > > Regards. > R. </Original message> <Reply> Ehhh... works fine here! Dunno what's wrong. Don't you do anything else within your code that can f#ck up the date? I have absolutely no problems with the piece of code you've send. I went through almost a complete year using the link it produces. No prob at all. Btw; you can just use: $yesternews = date("Y-m-d", mktime(0,0,0,$regs[2],$regs[3]-1,$regs[1])); PHP will make sure it produces a correct date. Then you don't have to works with timestamps and seconds and stuff. Just let PHP do all the work. That's what it's designed for :) </Reply> -- * R&zE: -- »»»»»»»»»»»»»»»»»»»»»»»» -- Renze Munnik -- DataLink BV -- -- E: renze@datalink.nl -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- ««««««««««««««««««««««««

« previous php.general (#67958) next »