RE: [PHP] Parsing HTML tags

From: Date: Fri, 13 Apr 2001 14:09:39 +0000
Subject: RE: [PHP] Parsing HTML tags
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-48444@lists.php.net to get a copy of this message
I use this function function title($filename,$dir) { $loc = "path/to/dir/where/file/is"; if(is_file("$loc/$filename")) { $open=fopen("$loc/$filename","r"); while(!feof($open)) { $line=fgets($open,255); $string = $line; while(ereg( '<title>([^<]*)</title>(.*)', $string, $regs ) ) { $string = $regs[2]; } } return $regs[1]; } } call it like so print(title("home.htm","web/articles")); The only drawback is if there is any < > tags in between the <title></title> tags it will not get the title, also if the title is on two lines like this <title>This is the title of my page</title> it won't get the title either. hth Thank you Brian Paulson Sr. Web Developer bpaulson@chieftain.com http://www.chieftain.com 1-800-269-6397 -----Original Message----- From: Chris Empson [mailto:C.J.Empson@chem.hull.ac.uk] Sent: Friday, April 13, 2001 8:45 AM To: php-general@lists.php.net Subject: [PHP] Parsing HTML tags Could anyone tell me how to extract a string from between a pair of HTML tags? Specifically, I would like to extract the page title from between the <title> and </title> tags. I have read the regular expression docs and I'm still a bit stuck. Can anyone help? Thanks in advance, Chris Empson C.J.Empson@chem.hull.ac.uk -- 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 (#48444) next »