From 8f786af4264f6ee88b043972645aafc038fa69db Mon Sep 17 00:00:00 2001 From: Mark Jaquith 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: https://develop.svn.wordpress.org/trunk@4386 602fd350-edb4-49c9-b593-d223f7449a82 --- 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 cb0b8eb950..a2c2e08fc5 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; }