note 55392 added to function.parse-url
| From: | jon_at_gaarsmand_dot_com at osu1 dot php dot net | Date: | Tue, 02 Aug 2005 07:51:43 +0000 |
| Subject: | note 55392 added to function.parse-url | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92931@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.parse-url.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55392
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55392&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55392&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55392&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55392&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55392&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55392&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55392&report=yes
Search -- http://master.php.net/manage/user-notes.php