PHP判断是否连接上网络

首先写个函数

function varify_url($url){
$check = @fopen($url,"r");
if($check){
 $status = true;
}else{
 $status = false;
}  
return $status;
}

接着在需要的地方直接调用即可

$url = "http://www.google.com";
if(varify_url($url)){
 echo "<div>Congratulation ! Your URL <a href=$url>$url</a>  : is <b>valid </b></div>";
}else{
 echo "<div>Error ! Your URL : <a href=$url>$url</a> is <b>invalid </b></div>";
}


你可能感兴趣的:(PHP,PHP,function,function,网络)