Regular Expressions and urls
| From: | Rob Gambit | Date: | Wed, 10 Oct 2001 14:54:49 +0000 |
| Subject: | Regular Expressions and urls | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-70678@lists.php.net to get a copy of this message | ||
I am trying to find a regex to relace a url in text with the <a href=... to
make it a link. The urls in the text are sometimes enclosed in () or []
Here is what I have now:
function make_url($txt){
return
eregi_replace("((ftp://)|(http://)|(www))(([a-z0-9.\-])*)(@)?(([a-z0-9\.])*)
(([:/])?)((([a-z0-9]*)(@?)/*)+([.a-z]{2,4}){1})?((\??[a-z0-9\=]*)?)((\&[a-z0
-9\=]*)?)(([\.a-z]){2,4})?", "<a href=\"\\0\"
target=\"_blank\">\\0</a>",$txt);
}
This works, except in some cases, like the following urls, the end path is
left off.
[http://www.geocities.com/Heartland/5792/]
[http://www.iidc.indiana.edu/~irca/]
Does anyone have something that will work with all urls?