Validate a url with PHP

Free Scripts :: PHP :: Validation :: Validate a url with PHP

Author: Salman Javaid

Website: http://www.salman.be

  • Validate a url with php.
  • How to validate a url with php.
  • Validate a url with php.

Function accepts a parameter and returns false if value is not a valid url.
Function
function isValidUrl($string){
if(!preg_match('/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i', $string)){
return false;
}
}
Calling The Function
$string=5;
if(isValidUrl($string)!==false){
echo 'Value is a valid url';
}else{
echo 'Value is not a valid url';
}
Output
Value is a valid url

Comments

No comments. Be the first one.

Leave a comment

Full Name*
Comments*
Security Code*

Our Partners

Getty Icons  Salman Creations
Free High Quality Images  Learn Free Languages 
Opal Hosting  R-Tech Solutions
  • Submit a Script

    Click here to submit your script.