21,886
社区成员
发帖
与我相关
我的任务
分享
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://qn.quotidiano.net/ultimora.php?news=135315570352&a=2012&m=11&g=17");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$htmls = curl_exec($ch);
curl_close($webch);
$htmls = utf8_encode(mb_convert_encoding($htmls, 'auto', 'UTF-8'));
//自动转换成utf8格式
libxml_use_internal_errors(true);
//去除dom保错
$dom = new DOMDocument('1.0', 'utf-8');
//声明DOM为utf8格式
@$dom->loadHTML($htmls);
$script_tags = $dom->getElementsByTagName('script');
$length = $script_tags->length;
for ($i = 0; $i < $length; $i++) {
$script_tags->item(0)->parentNode->removeChild($script_tags->item(0));
}
//查找script标签并去除
$dom->formatOutput = true;
$htmls = $dom->saveHTML();
//保存dom
echo $htmls;