Starting from PHP 5.2 we have bunch of built-in functions which makes it easier for programmers to perform small functions without writing up code for them,one of such function is filter_var(); , using filter_var().
We can validate emails and URL's easily with just a few steps or you can say only 4-5 lines of code, so lets say you want to validate a URL using filter_var() you can do it as follow:
To use this function simply use the following code :
if(checkurl("http://www.google.com")) {
echo 'URL is correct';
//continue....
}else{
echo 'URL is incorrect';
//through an error!
}
Simple isn't? And if you don't want to use the complete function,you can simply use the filter_var("Your URL here!", FILTER_VALIDATE_URL); .
Comments are welcome, and once more you must have PHP >= 5.2.
PHP
,
Tricks
,
URL
,
Validate
We can validate emails and URL's easily with just a few steps or you can say only 4-5 lines of code, so lets say you want to validate a URL using filter_var() you can do it as follow:
function checkurl($url)
return filter_var($url, FILTER_VALIDATE_URL);
}
To use this function simply use the following code :
if(checkurl("http://www.google.com")) {
echo 'URL is correct';
//continue....
}else{
echo 'URL is incorrect';
//through an error!
}
Simple isn't? And if you don't want to use the complete function,you can simply use the filter_var("Your URL here!", FILTER_VALIDATE_URL); .
Comments are welcome, and once more you must have PHP >= 5.2.
♥ Happy Coding.! ♥
thanks, the blog php tips tricks the programmers to perform small functions without writing up code for the good information.
ReplyDelete