How to validate url in php

php

Posted on 13 Feb 15 by Vickey
  429



Create a function

function isValidURL($url)
    {
        return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
    }

and use it as

$url='www.example.com';
isValidURL($url);

If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com