判断一个网页是不是404状态,可以使用PHP的CURLl检查检查网页是不是404状态
function chkurl($url){
$handledd = curl_init($url);
curl_setopt($handledd, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($handledd, CURLOPT_CONNECTTIMEOUT, 10);//设置超时时间
curl_exec($handledd);
//检查是否404(网页找不到)
$httpCode = curl_getinfo($handledd, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
return false;
}else{
return true;
}
curl_close($handledd);
}调用方法:
$url="http://m.sohu.com/a/357972719_99894142";
if(chkurl($url)==true){
echo "存在";
}else{
echo "不存在";
}