Entry
In my search engine result outputs, how can I make it to show page title?
Aug 26th, 2002 17:52
Nick Brandt, Nick Tucker, Tobias Talltorp
I assume that at some stage you open and index/extract data from a
page, to get the title from that page you can use the code below:
// 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 now contains title, 'AltaVista - The Search Company'
$title = $tag_contents[1];