FILTER_VALIDATE_URL 过滤器把值作为 URL 进行验证。
可能的标志:
<?php
$url = "http://www.example.com";
if(!filter_var($url, FILTER_VALIDATE_URL
))
{
echo "URL is not valid";
}
else
{
echo "URL is valid";
}
?>
输出:
URL is valid
<?php
$url = "example.php?name=Peter&age=37";
if(!filter_var($url, FILTER_VALIDATE_URL
, FILTER_FLAG_QUERY_REQUIRED))
{
echo "URL is not valid";
}
else
{
echo "URL is valid";
}
?>
输出:
URL is valid