note 95057 deleted from ref.mbstring by danbrown

From: Date: Fri, 11 Dec 2009 16:20:55 +0000
Subject: note 95057 deleted from ref.mbstring by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-163862@lists.php.net to get a copy of this message
Note Submitter: awinter (AT) daimon soft dot com ---- small change to peter AT(no spam) dezzignz dot com's mb_trim function to make it work more like trim rather than only removing the full $rem string if it matches 100% and also to remove multi-byte spaces by default. <?php // multibyte string split function mbStringToArray($str) { if (empty($str)) return false; $len = mb_strlen($str); $array = array(); for ($i = 0; $i < $len; $i++) { $array[] = mb_substr($str, $i, 1); } return $array; } // removes $rem at both ends function mb_trim ($str, $rem = '  ') { if (empty($str)) return false; // convert to array $arr = mbStringToArray($str); $rem = mbStringToArray($rem); $len = count($arr); // left side for ($i = 0; $i < $len; $i++) { if (in_array($arr[$i], $rem)) $arr[$i] = ''; else break; } // right side for ($i = $len-1; $i >= 0; $i--) { if (in_array($arr[$i], $rem)) $arr[$i] = ''; else break; } // convert to string return implode ('', $arr); } ?>

« previous php.notes (#163862) next »