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
[EMAIL PROTECTED]
http://www.chieftain.com
1-800-269-6397
-----Original Message-----
From: Chris Empson [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 13, 2001 8:45 AM
To: [EMAIL PROTECTED]
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
[EMAIL PROTECTED]
--
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 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]