RE: [PHP] Regular Explression

From: Date: Mon, 06 Nov 2000 22:48:56 +0000
Subject: RE: [PHP] Regular Explression
Groups: php.general 
Request: Send a blank email to php-general+get-23998@lists.php.net to get a copy of this message
I think you should read the regular expression help page on php.net. Something like this is probably best done in a couple of passes to make it cleaner and more generic, as it is what happens if the table changes slightly .. you need a big new reg exp. Make from get the whole file, ie $from .= fgets($file, 1024); Then do something like, preg_match("/<table.*\/table>/im", $from, $tablematch); preg_match("/MonthViewDateNumber.*?>([::digit::]+)/i", $tablematch[0], $datenumber); preg_match("/MonthViewDayOfWeek.*?>([::alpha::]+)/i", $tablematch[0], $dayofweek); not tested but hope this gives you a few ideas, Nick > -----Original Message----- > From: Holev` [mailto:webmaster@builder.co.il] > Sent: Tuesday, 7 November 2000 9:30 > To: php-general@lists.php.net > Subject: [PHP] Regular Explression > > > Hey, > I have something like this in a file: > <table width=100% cellspacing=0 > cellpadding=0 border=0> > <tr><td width=2% rowspan=2>&nbsp;</td> > <td width=6% valign=top class=MonthViewDateNumber > rowspan=2>5&nbsp;</td> > <td width=90% valign=top > class=MonthViewDayOfWeek>Sunday&nbsp;</td> > <td width=2% rowspan=2>&nbsp;</td></tr> > <tr><td width=90%> > > > > > > > </td></tr> > </table> > > and I made this file to get the information from it: > <? > if($file = fopen("d:/cal.html", "r")) { > while(!feof($file)) { > $from = fgets($file, 1024); > ereg(" > <table width=100% cellspacing=0 > cellpadding=0 border=0> > <tr><td width=2% rowspan=2>&nbsp;</td> > <td width=6% valign=top class=MonthViewDateNumber > rowspan=2>(.*)&nbsp;</td> > <td width=90% valign=top > class=MonthViewDayOfWeek>(.*)&nbsp;</td> > <td width=2% rowspan=2>(.*)</td></tr> > <tr><td width=90%> > (.*) > </td></tr> > </table> > ",$from,$to); > echo $to[0]; > } > } > ?> > > what am I doing worng? > should I put \n instead of actual new lines? > > thanx. > > -- > _______________________________________________ > David Berlin > webmaster@builder.co.il > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: > php-list-admin@lists.php.net > >

« previous php.general (#23998) next »