Re: [PHP] Re: I suck at regular expressions!
Not quite. I have the same problem. At 11:36 PM 11/14/2001, Johan Holst Nielsen wrote: Richard S. Crawford wrote: 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); } Try: function getTitle($filename) { $fp = fopen($filename, r); $filecontent = fread($fp, filesize($filename)); if(eregi(title(.+)/title, $content, $title_arr)) { return addslashes(htmlspecialchars(trim(strip_tags($title_arr[1]; } else { return (No Title); } } Regards, Johan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] Sliante, Richard S. Crawford http://www.mossroot.com mailto:[EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Re: I suck at regular expressions!
Richard S. Crawford wrote: Not quite. I have the same problem. I tried at test on my localhost. Following works for me: $string = htmlheadtitleSometime i dont wanna know/title/headbody/body/html; if(eregi(title(.+)/title, $string, $arr)) { echo Title: .$arr[1]; } else { echo unknown title; } This works for me? Regards, Johan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: I suck at regular expressions!
try that! ? $mem=' !doctype html public -//W3C//DTD HTML 4.0 Transitional//EN html head title New Document /title meta name=Author content= meta name=Keywords content= meta name=Description content= /head body /body /html '; if (preg_match('/title(.+?)\/title/is', $mem, $matches)) { echo title is:$matches[1]; } ? Richard S. Crawford [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... 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:[EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Re: I suck at regular expressions!
Actually, that does work when I'm using a string with that content. The only thing I can figure is that there is a problem with the way the the file is being read. Hmm. Ah, well. I'll make it work. Where's my hammer? At 12:18 AM 11/15/2001, Johan Holst Nielsen wrote: Richard S. Crawford wrote: Not quite. I have the same problem. I tried at test on my localhost. Following works for me: $string = htmlheadtitleSometime i dont wanna know/title/headbody/body/html; if(eregi(title(.+)/title, $string, $arr)) { echo Title: .$arr[1]; } else { echo unknown title; } This works for me? Regards, Johan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] Sliante, Richard S. Crawford http://www.mossroot.com mailto:[EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: I suck at regular expressions!
Richard S. Crawford wrote: 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); } Try: function getTitle($filename) { $fp = fopen($filename, r); $filecontent = fread($fp, filesize($filename)); if(eregi(title(.+)/title, $content, $title_arr)) { return addslashes(htmlspecialchars(trim(strip_tags($title_arr[1]; } else { return (No Title); } } Regards, Johan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]