php检查URL是否有效
AI摘要
本文介绍了一个PHP函数,用于检查URL是否有效。函数首先检查URL是否包含http://,如果没有则添加。然后使用get_headers函数获取URL的头部信息,通过检查返回的状态码判断URL是否存在。如果状态码为404,则输出“此地址不存在”;否则输出“此地址正确”。
function checkUrl($url){
if(stripos($url,'http://') === FALSE){
$url = 'http://'.$url;
}
@$rs = get_headers($url);
if($rs){
if(stripos($rs[0],'404') !== FALSE){
echo '此地址不存在';
}else{
echo '此地址正确';
}
}else{
echo '此地址不存在';
}
}
读者留言 0 条
一纸留言,便是山水间的一次相逢。
还没有留言,欢迎写下第一段交流。