tags:

views:

52

answers:

3

Hi, I want to retrieve the title of the cricinfo.com webpage. How to retrieve it using php. Please help me

+1  A: 

You can use something to get the source of the webpage. Then look for the position of the <title> substring (call it start_index...add 7 to it because <title> is 7 chars long)). Also look for the position of the </title> substring (call it end_index). The title of that page is the substring bewteen start_index and end_index.

milesmeow
+2  A: 

Here's a way to do it via a reg exp ::ducks::

$url = 'http://stackoverflow.com/questions/1811616/how-to-retrieve-the-title-part-of-other-web-page-like-google-or-yahoo-using-php';
preg_match('~<title>(.*?)</title>~i', file_get_contents($url), $match);
echo $match[1];
Galen