php中检查某个网页地址是否有效能被打开的最简单方法:使用fopen函数
fopen — 打开文件或者 URL:
resource fopen ( string $filename , string $mode [, bool $use_include_path [, resource $zcontext ]] )
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 将检查并确认 allow_url_fopen 已被激活。如果关闭了,PHP 将发出一个警告,而 fopen 的调用则失败。