Code Snippet
URL Validation
$url = 'http://example.com';
$validation = filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED);
if ( $validation ) $output = 'proper URL';
else $output = 'wrong URL';
echo $output;$url = 'http://example.com';
$validation = filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED);
if ( $validation ) $output = 'proper URL';
else $output = 'wrong URL';
echo $output;
$output = ‘proper UL’;
I think there is a typo in that line.
I think it needs improvements. The code will pass the url “http://www.example” as valid url.
filter_var is good one but I still have faith in good old preg_match() and the regular expressions.
preg_match(“#^http(s)?://[a-z0-9-_.]+\.[a-z]{2,4}#i”,$url);
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.