note 22700 deleted from function.preg-replace by sniper

From: Date: Sun, 07 Sep 2003 22:06:16 +0000
Subject: note 22700 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55704@lists.php.net to get a copy of this message
Note Submitter: andy@ldg.net ---- Makes hyperlinks and mailtos from user input readable as per above comments, but traps for "."s on the end of inputs as well as delimiting end of linkable text by a whitespace as opposed to just grabbing the next word after www or http:\\ (it broke for www.this-that.com) . Thanks to all you regex gods for any number of times where you have saved me from hours of toil.. $message = preg_replace("/((http(s?):\/\/)|(www\.))([\S\.]+)\b/i", "<a href=\"http$3://$4$5\" target=\"_blank\">$2$4$5</a>", $message); $description = preg_replace("/([\w\.]+)(@)([\S\.]+)\b/i", "<a href=\"mailto:$0\">$0</a>", $description);

« previous php.notes (#55704) next »