声明
部分内容来自网络 本教程仅用于学习, 禁止用于其他用途
<?php
/* php使用curl判断404
* Created on 2016-6-22
* Writer www.jb51.net
*/
function chkurl($url){
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 10);//设置超时时间
curl_exec($handle);
//检查是否404(网页找不到)
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
return false;
}else{
return true;
}
curl_close($handle);
}
$url="网址填写在这里";
if(chkurl($url)==true){
echo "存在";
}else{
echo "不存在";
}
?>
文本操作
$myfile = fopen("1.txt", "w") or die("Unable to open file!");
$txt = “hello” ;
fwrite($myfile, $txt);
fclose($myfile);
echo "处理完毕";
|