note 22700 added to function.preg-replace

From: Date: Thu, 27 Jun 2002 00:41:22 +0000
Subject: note 22700 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-32254@lists.php.net to get a copy of this message
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); -- http://www.php.net/manual/en/function.preg-replace.php http://master.php.net/manage/user-notes.php?action=edit+22700 http://master.php.net/manage/user-notes.php?action=delete+22700 http://master.php.net/manage/user-notes.php?action=reject+22700

« previous php.notes (#32254) next »