公告
财富商城
积分规则
提问
发文
2019-03-04 18:42发布
爱情/是我丢掉的垃圾
Possible Duplicate: Best methods to parse HTML
How do I extract title of a website using PHP?
You can get the domain name through $_SERVER['HTTP_HOST'].
$_SERVER['HTTP_HOST']
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).
//title
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];
最多设置5个标签!
You can get the domain name through
$_SERVER['HTTP_HOST']
.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).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: