开发者

How to retrieve the title part of other web page like google or yahoo using php?

开发者 https://www.devze.com 2022-12-13 04:44 出处:网络
I want to retrieve the title of the cricinfo.com webpage. How to retrieve开发者_JS百科 it using php. Please help meHere\'s a way to do it via a reg exp ::ducks::

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消