How do I extract title of a website? [duplicate]

老子叫甜甜 提交于 2019-12-02 17:40:33

问题


Possible Duplicate:
Best methods to parse HTML

How do I extract title of a website using PHP?


回答1:


To manupulate with HTML you can use Document Object Model (this is the recomended way).

If you are looking for a dirty fast solution, it's rather simple regexp:

$html = file_get_contents('http://example.com');
$matches = preg_match("/<title>([^<]*)<\/title>/im");
echo $matches[1];



回答2:


You can get the domain name through $_SERVER['HTTP_HOST'].




回答3:


Grab the document using curl, run it through a parser and then use whatever API that parser provides to get the title element (//title will do if there is XPath support).



来源:https://stackoverflow.com/questions/5869088/how-do-i-extract-title-of-a-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!