php URL 是否有效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6806929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
is URL valid or not
提问by james
Possible Duplicate:
what is the best way to check if a Url exists in PHP ?`
I'm looking for a function that returns TRUE or FALSE in php, either the URL is valid or not.
我正在寻找一个在 php 中返回 TRUE 或 FALSE 的函数,无论 URL 是否有效。
isValidURL($url); i think that simple... That would take into count all kind of URL possible.
isValidURL($url); 我认为这很简单...这将考虑所有可能的 URL。
By valid i want It to referes to an existing page of the web or other kind of files. It just should exist
通过有效,我希望它引用网络的现有页面或其他类型的文件。它应该存在
回答by genesis
<?php
$url = "http://stack*overflow.org";
if(filter_var($url, FILTER_VALIDATE_URL) === FALSE)
{
echo "Not valid";
}else{
echo "VALID";
}
?>
this does not check tldsthough
虽然这不会检查tlds