note 29803 deleted from function.preg-replace by sniper

From: Date: Sun, 07 Sep 2003 22:02:48 +0000
Subject: note 29803 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55688@lists.php.net to get a copy of this message
Note Submitter: php (at) greywyvern dot com ---- Closer to the Holy Grail... Same function as before (see above a couple spots), but now using forward and back references. Will spot and trim URLs which end in more than one non-word chracter. So: www.someurl.com!!?!?! Becomes: <a href="http://www.someurl.com">www.someurl.com</a>!!?!?! function addLinks($string) { $string = preg_replace( "/(?<!quot;|[=\"]|:\/\/)\b((\w+:\/\/|www\.).+?)". "(?=\W*([<>\s]|$))/i", "<a href=\"$1\">$1</a>", $string); return preg_replace("/href=\"www/i", "href=\"http://www", $string);} Enjoy, I hope! :) Grey

« previous php.notes (#55688) next »