为什么要剥离HTML?最好使用它!
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$data = curl_exec($ch);
curl_close($ch);
// libxml_use_internal_errors(true);
$oDom = new DomDocument();
$oDom->loadHTML($data);
// Go through DOM and look for error (it's similar if it'd be
// <p class="error">error message</p> or whatever)
$errors = $oDom->getElementsByTagName("error"); // or however you get errors
foreach($errors as $error) {
if(strstr($error->nodeValue, 'SOME ERROR')) {
echo 'SOME ERROR occurred';
}
}
如果你不想做,你可以这样做:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$data = curl_exec($ch);
curl_close($ch);
if(strstr($data, 'SOME_ERROR')) {
echo 'SOME ERROR occurred';
}
来源
2012-07-17 13:33:12
Doa
要清楚你想从网络上删除HTML标记并获得唯一剩余的数据? – Nish 2012-07-17 13:16:44
你好,我希望得到处理后的内容,就像在加载javascript和生成内容之后。不是一个查看源的JavaScript和功能仍然存在,然后剥离他们的标签。我应该举个例子来更好地解释我自己:) – user1531773 2012-07-17 16:23:48