Re: Parsing HTML tags
| From: | Tobias Talltorp | Date: | Fri, 13 Apr 2001 14:19:25 +0000 |
| Subject: | Re: Parsing HTML tags | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-48445@lists.php.net to get a copy of this message | ||
// Get the webpage into a string
$html = join ("", file ("http://www.altavista.com"));
// Using eregi
eregi("<title>(.*)</title>", $html, $tag_contents);
// Using preg_match (faster than eregi)
// The i in the end means that it is a case insensitive match
preg_match("/<title>(.*)<\/title>/i", $html, $tag_contents);
$title = $tag_contents[1];
// Tobias
"Chris Empson" <C.J.Empson@chem.hull.ac.uk> wrote in message
news:9b6vkl$jpf$1@toye.p.sourceforge.net...
> 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
>