0

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

Rajasekar
  • 18,392
  • 34
  • 106
  • 137

2 Answers2

2

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
  • 29,976
  • 9
  • 71
  • 89
1

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
  • 3,688
  • 5
  • 35
  • 58