How to retrieve the title part of other web page like google or yahoo using php?
I want to retrieve the title of the cricinfo.com webpage. How to retrieve开发者_JS百科 it using php. Please help me
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];
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.
精彩评论