note 13653 added to function.ereg-replace.php
| From: | mwhitlock at whitsoftdev dot com dot nospam | Date: | Wed, 27 Jun 2001 05:44:22 +0000 |
| Subject: | note 13653 added to function.ereg-replace.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-14693@lists.php.net to get a copy of this message | ||
I've seen several methods listed here about how to convert URL's into hyperlinks, but none
are really satisfactory. What about other protocols besides HTTP? And surrounding punctuation should
not be included.
Here is my thoroughly stress-tested solution:
ereg_replace("[A-Za-z]+://[^ <>\n]*[A-Za-z0-9/]", '<a
href="\\0">\\0</a>', $var);
Sure is a lot simpler than a lot of the others, and it works flawlessly on every URL I've
tested, even complicated ones with query strings or PHP session id's! It excludes any
surrounding puctuation, like if your URL has a period after it as the end of a sentence. ;-)
http://www.php.net/manual/en/function.ereg-replace.php