From 3d71ec438403ec0420c1c50bb7b6175cf160c338 Mon Sep 17 00:00:00 2001 From: markjaquith Date: Fri, 13 Oct 2006 06:01:14 +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/branches/2.0@4385 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions-formatting.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/wp-includes/functions-formatting.php b/wp-includes/functions-formatting.php index 3b7b843f37..b6105c693e 100644 --- a/wp-includes/functions-formatting.php +++ b/wp-includes/functions-formatting.php @@ -589,12 +589,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; }