note 29349 deleted from function.preg-replace by tularis
| From: | tularis@php.net | Date: | Sun, 18 Jun 2006 13:14:15 +0000 |
| Subject: | note 29349 deleted from function.preg-replace by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114323@lists.php.net to get a copy of this message | ||
Note Submitter: toxic79_spam at yahoo dot com
----
here's another way to link urls in text. unlike the others i see here, this one doesn't
link urls that have already been linked so you won't get <a href="<a href="http://www.blah.com">http://www.blah.com</a>">link</a>
if your text ($txt) already has links in it.
it's been quickly tested with uppercase, lowercase, http and ftp, secure urls, ports and query
strings. it won't work if the url has spaces in it, but if you convert them to %20 it'll
be ok.
$txt = preg_replace( "/(?<!<a href=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i",
"<a href=\"\\0\">\\0</a>", $txt );