From 690819315138830384b4eb45dd77e65a3866cb1a Mon Sep 17 00:00:00 2001 From: gregb_cc Date: Wed, 12 Mar 2003 21:37:05 +0000 Subject: [PATCH] speed improvement in smilie_replace. It is now almost as fast (within 5-10%) of the version that used global smilie definitions. --- lib/weblib.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index 3a010c1221..e109b8f248 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -474,7 +474,8 @@ function replace_smilies($text) { global $CFG; static $runonce = false; - static $smilies = false; + static $e = array(); + static $img = array(); static $emoticons = array( ':-)' => 'smiley.gif', ':)' => 'smiley.gif', @@ -502,12 +503,13 @@ function replace_smilies($text) { if($runonce == false): foreach ($emoticons as $emoticon => $image){ - $smilies[$emoticon] = "\"$emoticon\"wwwroot}/pix/s/{$image}\">"; + $e[] = $emoticon; + $img[] = "\"$emoticon\"wwwroot}/pix/s/{$image}\">"; } $runonce = true; endif; - return strtr($text, $smilies); + return str_replace($e, $img, $text); } function text_to_html($text, $smiley=true, $para=true) { -- 2.39.5