PHP中使用CURL获取页面title例子
通过PHP获取页面title内容的实战演示: 范例代码: 代码如下: 内容
参数:$_POST['url'] // 设置最长执行的秒数 // 检查 URL / 取得 URL 页面数据 / // 设置 URL // 尝试取得文件内容 // 检查文件是否正确取得 // 关闭 CURL // 解析 HTML 的 区段preg_match("/<head.>(.)</head>/smUi",$store,$htmlHeaders); if(!count($htmlHeaders)){ echo "无法解析数据中的 区段"; exit; } // 取得 中 meta 设置的编码格式if(preg_match("/<meta[^>]http-equiv[^>]charset=(.*)("|')/Ui",$htmlHeaders[1],$results)){ $charset = $results[1]; }else{ $charset = "None"; } // 取得 if(preg_match("/ if(!count($htmlTitles)){ echo "无法解析 exit; } // 将 if($charset == "None"){ $title=$htmlTitles[1]; }else{ $title=iconv($charset,"UTF-8",$htmlTitles[1]); } echo $title; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |