Show
Ignore:
Timestamp:
11/25/2007 04:09:46 AM (12 months ago)
Author:
Geert
Message:

Fixing bugs #236, #237 and #239.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/helpers/text.php

    r1250 r1258  
    2323         *  A word-limited string with the end character attached. 
    2424         */ 
    25         public static function limit_words($str, $limit = 100, $end_char = '…') 
     25        public static function limit_words($str, $limit = 100, $end_char = NULL) 
    2626        { 
    2727                $limit = (int) $limit; 
     28                $end_char = ($end_char === NULL) ? '…' : $end_char; 
    2829 
    2930                if (trim($str) == '') 
     
    141142 
    142143                $str = ''; 
    143                 $pool_size = utf8::strlen($pool); 
     144                $pool_size = (class_exists('utf8', FALSE)) ? utf8::strlen($pool) : strlen($pool); 
    144145 
    145146                for ($i = 0; $i < $length; $i++) 
    146147                { 
    147                         $str .= utf8::substr($pool, mt_rand(0, $pool_size - 1), 1); 
     148                        $str .= (class_exists('utf8', FALSE)) ? utf8::substr($pool, mt_rand(0, $pool_size - 1), 1) : substr($pool, mt_rand(0, $pool_size - 1), 1); 
    148149                } 
    149150 
     
    196197                $regex = '!'.$regex.'!ui'; 
    197198 
    198                 if (utf8::strlen($replacement) == 1) 
     199                $strlen = (class_exists('utf8', FALSE)) ? utf8::strlen($replacement) : strlen($replacement); 
     200                if ($strlen == 1) 
    199201                { 
    200202                        $regex .= 'e'; 
    201                         return preg_replace($regex, 'str_repeat($replacement, utf8::strlen(\'$1\'))', $str); 
     203                        return preg_replace($regex, 'str_repeat($replacement, (class_exists(\'utf8\', FALSE)) ? utf8::strlen(\'$1\') : strlen(\'$1\'))', $str); 
    202204                } 
    203205