note 34999 deleted from function.preg-replace by sniper

From: Date: Sun, 07 Sep 2003 21:55:46 +0000
Subject: note 34999 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55666@lists.php.net to get a copy of this message
Note Submitter: Tarmo Renter <tarmo@momentor.ee> ---- The code below is a bit modified variant of one of automatic-hyperlinkers above (accepts http, https, ftp protocol URLs, also email address), this one also accpets Apache /~user functionality: $text = preg_replace("/(?:^|\b)((((http|https|ftp):\/\/)|(www\.)) ([\w\.]+)([,:%#&\/?~=\w+\.-]+))(?:\b|$)/is", "<a href=\"$1\" target=\"_blank\">$1</a>", $text); $text = preg_replace("/(([\w\.]+))(@)([\w\.]+)\b/i","<a href=\"mailto:$0\">$0</a>",$text); If you have a string with tags , including for example <img src=http:///www.qwe.ee/img.jpg>, you might want to add negative lookbehinds, (?<!\/)(?<!=) before ((((http|https|ftp). This excludes URLs, which begin with / and =

« previous php.notes (#55666) next »