Changeset 1258 for trunk/system/helpers/text.php
- Timestamp:
- 11/25/2007 04:09:46 AM (12 months ago)
- Files:
-
- 1 modified
-
trunk/system/helpers/text.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/helpers/text.php
r1250 r1258 23 23 * A word-limited string with the end character attached. 24 24 */ 25 public static function limit_words($str, $limit = 100, $end_char = '…')25 public static function limit_words($str, $limit = 100, $end_char = NULL) 26 26 { 27 27 $limit = (int) $limit; 28 $end_char = ($end_char === NULL) ? '…' : $end_char; 28 29 29 30 if (trim($str) == '') … … 141 142 142 143 $str = ''; 143 $pool_size = utf8::strlen($pool);144 $pool_size = (class_exists('utf8', FALSE)) ? utf8::strlen($pool) : strlen($pool); 144 145 145 146 for ($i = 0; $i < $length; $i++) 146 147 { 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); 148 149 } 149 150 … … 196 197 $regex = '!'.$regex.'!ui'; 197 198 198 if (utf8::strlen($replacement) == 1) 199 $strlen = (class_exists('utf8', FALSE)) ? utf8::strlen($replacement) : strlen($replacement); 200 if ($strlen == 1) 199 201 { 200 202 $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); 202 204 } 203 205
