0
我需要一段代码来检查是否输入了URL。检查是否已输入网址
$url = 'localhost/index.php';
if($url){
echo "index.php is correct";
} else {
header('localhost/...');
}
我需要一段代码来检查是否输入了URL。检查是否已输入网址
$url = 'localhost/index.php';
if($url){
echo "index.php is correct";
} else {
header('localhost/...');
}
如果你想检查变量$url
设置,那么你应该使用isset()
。
如果你想检查变量$url
具有值即不 NULL,FALSE,0或空字符串,那么你就应该使用empty()
如果你想检查并看看是否存在一个文件,你应该使用Apache的.htaccess
文件让PHP知道。 (See this question)或者,您可以尝试解析路径的URL,并使用file_exists()
和is_file()
来确定路径是否存在并且实际上是文件。
如果你想知道,如果变量的值是URL的有效的类型,你正在寻找parse_url()
和filter_var()
你想验证URL或只是检查“的index.php”在这里? –