爲什麼要剝離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