note 55392 deleted from function.parse-url by didou
| From: | didou@php.net | Date: | Sat, 03 Feb 2007 03:08:01 +0000 |
| Subject: | note 55392 deleted from function.parse-url by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-122615@lists.php.net to get a copy of this message | ||
Note Submitter: jon _at_ gaarsmand _dot_ com
----
Some developers look here for a mean of validating an url. So here is a simple way of validating an
url.
$uri = 'http://some-domain-name.org';
if( preg_match( '/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}'
.'((:[0-9]{1,5})?\/.*)?$/i' ,$uri))
{
echo $uri . ' is a valid url';
}
else
{
echo $uri . ' is NOT a valid url';
}
Beware - it only validates scemes: http and https, and it only takes into account host and port part
of the uri. It does not accept username and password.
For an email validator you could look at http://gaarsmand.com/index.php/IT_l%F8sninger/Kode_eksempler/PHP_kode.