]> git.mjollnir.org Git - moodle.git/commitdiff
speed improvement in smilie_replace. It is now almost as fast (within 5-10%) of
authorgregb_cc <gregb_cc>
Wed, 12 Mar 2003 21:37:05 +0000 (21:37 +0000)
committergregb_cc <gregb_cc>
Wed, 12 Mar 2003 21:37:05 +0000 (21:37 +0000)
the version that used global smilie definitions.

lib/weblib.php

index 3a010c1221303c7d2f32bede148bac3cd62ea32b..e109b8f2489b4b72605df638de5800b349b2952d 100644 (file)
@@ -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] = "<IMG ALT=\"$emoticon\" WIDTH=15 HEIGHT=15 SRC=\"{$CFG->wwwroot}/pix/s/{$image}\">";
+            $e[] = $emoticon;
+            $img[] = "<IMG ALT=\"$emoticon\" WIDTH=15 HEIGHT=15 SRC=\"{$CFG->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) {