faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 11 people (55%) answered Yes
Recently 6 of 10 people (60%) answered Yes


In my search engine result outputs, how can I make it to show page title?

Feb 27th, 2008 00:03
dman, Nick Brandt, Nick Tucker, http://www.ttnr.org

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];