<?php
$urls = array(
'http://www.website.com/path1/path2/file1.php?query1=true&query2=false',
'http://website.com/path1/path2/file1.php?query1=true&query2=false',
'http://website/path1/path2/file1.php?query1=true&query2=false',
'http://www.website.com/path1/path2/?query1=true&query2=false',
'http://website.com/path1/path2/?query1=true&query2=false',
'http://website/path1/path2/?query1=true&query2=false',
'http://www.website.com/path1/path2/',
'http://website.com/path1/path2/',
'http://website/path1/path2/',
'http://www.website.com?query1=true&query2=false',
'http://website.com?query1=true&query2=false',
'http://website?query1=true&query2=false',
'www.website.com/path1/path2/file1.php?query1=true&query2=false',
'website.com/path1/path2/file1.php?query1=true&query2=false',
'website/path1/path2/file1.php?query1=true&query2=false',
'www.website.com/path1/path2/?query1=true&query2=false',
'website.com/path1/path2/?query1=true&query2=false',
'website/path1/path2/?query1=true&query2=false',
'www.website.com/path1/path2/',
'website.com/path1/path2/',
'website/path1/path2/',
'www.website.com?query1=true&query2=false',
'website.com?query1=true&query2=false',
'website?query1=true&query2=false',
);
$flags = array(
null,
FILTER_FLAG_SCHEME_REQUIRED,
FILTER_FLAG_SCHEME_REQUIRED & FILTER_FLAG_HOST_REQUIRED,
FILTER_FLAG_SCHEME_REQUIRED & FILTER_FLAG_HOST_REQUIRED & FILTER_FLAG_PATH_REQUIRED,
FILTER_FLAG_SCHEME_REQUIRED & FILTER_FLAG_HOST_REQUIRED & FILTER_FLAG_PATH_REQUIRED & FILTER_FLAG_QUERY_REQUIRED
);
foreach($urls as $url){
foreach($flags as $flag){
var_dump((bool) filter_var($url, FILTER_VALIDATE_URL, $flag));
}
echo "<br/>";
}
preferences:
35.53 ms | 402 KiB | 5 Q