RE: [PHP] I suck at regular expressions!

From: Date: Thu, 15 Nov 2001 16:04:53 +0000
Subject: RE: [PHP] I suck at regular expressions!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-74717@lists.php.net to get a copy of this message
Been Using this Function for some time and works real well with two exceptions 1. if the title line has a CR in it it will no get the title Example: <title>This is a bad Title</title> 2. If there are any other < > tags in the title it will fail. <? function title($file) { $loc = "/path/to/file"; if(is_file("$loc/$file")) { $open=fopen("$loc/$file","r"); while(!feof($open)) { $line=fgets($open,1000); // this is set large due to some of the long title we have $string = $line; while ( eregi( '<headline>([^<]*)</headline>(.*)', $string, $regs ) ) { $string = $regs[2]; } } return $regs[1]; } } ?> -----Original Message----- From: Richard S. Crawford [mailto:rscrawford@mossroot.com] Sent: Wednesday, November 14, 2001 11:30 PM To: php-general@lists.php.net Subject: [PHP] I suck at regular expressions! I am trying to get the title of an html file... you know, the string between the < title > and < /title > tags... Here is the function I've got so far: function fileTitle($fileName) { $myFile = fopen($fileName, "r"); $myText=""; while (!feof($myFile)) { $myText .= fgets($myFile,255); } fclose($myFile); if (eregi("<TITLE>(.+)</TITLE>",$myText,$theTitle)) return $theTitle[0]; else return "(No Title)"; } The trouble is, it always returns "(No Title)", regardless of whether the file has a title defined in the header or not. I suspect I'm doing something fundamentally wrong. Can anyone set me straight? Sliante, Richard S. Crawford http://www.mossroot.com mailto:rscrawford@mossroot.com AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford "It is only with the heart that we see rightly; what is essential is invisible to the eye." --Antoine de Saint Exupéry "Push the button, Max!" -- 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 (#74717) next »