note 13653 deleted from function.ereg-replace by jimw

From: Date: Fri, 02 Nov 2001 01:58:25 +0000
Subject: note 13653 deleted from function.ereg-replace by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20212@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. ;-)

« previous php.notes (#20212) next »