note 93824 added to function.preg-match
| From: | splattermania at freenet dot de | Date: | Thu, 01 Oct 2009 12:01:00 +0000 |
| Subject: | note 93824 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161200@lists.php.net to get a copy of this message | ||
As I wasted lots of time finding a REAL regex for URLs and resulted in building it on my own, I now
have found one, that seems to work for all kinds of urls:
<?php
$regex = "((https?|ftp)\:\/\/)?"; // SCHEME
$regex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?"; // User
and Pass
$regex .= "([a-z0-9-.]*)\.([a-z]{2,3})"; // Host or IP
$regex .= "(\:[0-9]{2,5})?"; // Port
$regex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?"; // Path
$regex .= "(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?"; // GET Query
$regex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?"; // Anchor
?>
If someone discovers URLs that don't match, please let me know.
Thank you!
----
Server IP: 217.160.72.57
Probable Submitter: 87.79.185.118
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- https://master.php.net/note/edit/93824
Del: integrated -- https://master.php.net/note/delete/93824/integrated
Del: useless -- https://master.php.net/note/delete/93824/useless
Del: bad code -- https://master.php.net/note/delete/93824/bad+code
Del: spam -- https://master.php.net/note/delete/93824/spam
Del: non-english -- https://master.php.net/note/delete/93824/non-english
Del: in docs -- https://master.php.net/note/delete/93824/in+docs
Del: other reasons-- https://master.php.net/note/delete/93824
Reject -- https://master.php.net/note/reject/93824
Search -- https://master.php.net/manage/user-notes.php