note 101051 deleted from function.chunk-split by danbrown

From: Date: Tue, 23 Nov 2010 15:09:50 +0000
Subject: note 101051 deleted from function.chunk-split by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174287@lists.php.net to get a copy of this message
Note Submitter: Felipe ---- <?php 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; } function mb_chunk_split($str, $len, $glue) { if (empty($str)) return false; $array = mbStringToArray ($str); $n = -1; $new = ''; foreach ($array as $char) { $n++; if ($n < $len) $new .= $char; elseif ($n == $len) { $new .= $glue . $char; $n = 0; } } return $new; }

« previous php.notes (#174287) next »