Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 卷曲页面标题_Php_Html_Curl - Fatal编程技术网

Php 卷曲页面标题

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$结果存储结果。查看分析结果的内容 或者使用正则表

我使用以下代码从指定页面获取完整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');