Php 卷曲页面标题
我使用以下代码从指定页面获取完整html:Php 卷曲页面标题,php,html,curl,Php,Html,Curl,我使用以下代码从指定页面获取完整html: $url = "http://www.google.com"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_close ($ch); 问题:如何修改此代码以返回而不是页面的完整html$结果存储结果。查看分析结果的内容 或者使用正则表
$url = "http://www.google.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close ($ch);
问题:如何修改此代码以返回
而不是页面的完整html$结果存储结果。查看分析结果的内容
或者使用正则表达式
或者Dom文档您可以使用正则表达式获取标题,我发现这个正则表达式非常有用:
function get_html_title($html){
preg_match("/\<title.*\>(.*)\<\/title\>/isU", $html, $matches);
return $matches[1];
}
函数get\u html\u title($html){
preg\u match(“/\(.*)\/isU”,$html,$matches);
返回$matches[1];
}
你不能只得到标题,你可以得到整个文档,然后删除你需要的元素:我喜欢使用
如果您阅读Google URL,您将获得页面的完整HTML,可能还有很多JavaScript内容。Ryan Naddy的正则表达式在我看来很正确。
$html = file_get_html('http://www.google.com/');
$title = $html->find('title');