From 6c5769cc4cbe4296e1ce30a0abeef87641330c63 Mon Sep 17 00:00:00 2001 From: markjaquith Date: Fri, 13 Oct 2006 06:01:33 +0000 Subject: [PATCH] make_clickable() now faster and supports more link positions, from mdawaffe and myself. fixes #3228 git-svn-id: http://svn.automattic.com/wordpress/trunk@4386 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index cb0b8eb95..a2c2e08fc 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -593,12 +593,20 @@ function antispambot($emailaddy, $mailto=0) { return $emailNOSPAMaddy; } -function make_clickable($ret) { +function make_clickable_mine4($ret) { $ret = ' ' . $ret; - $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "$1$2", $ret); - $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "$1$2", $ret); - $ret = preg_replace("#(\s)([a-z0-9\-_.]+)@([^,< \n\r]+)#i", "$1$2@$3", $ret); - $ret = substr($ret, 1); + // in testing, using arrays here was found to be faster + $ret = preg_replace( + array( + '#([\s>])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is', + '#([\s>])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is', + '#([\s>])([a-z0-9\-_.]+)@([^,< \n\r]+)#i'), + array( + '$1$2', + '$1$2', + '$1$2@$3'),$ret); + // this one is not in an array because we need it to run last, for cleanup of accidental links within links + $ret = preg_replace("#(]+?>|>))]+?>([^>]+?)#i", "$1$3", $ret); $ret = trim($ret); return $ret; }