note 97156 added to function.chunk-split

From: Date: Mon, 05 Apr 2010 11:30:57 +0000
Subject: note 97156 added to function.chunk-split
Groups: php.notes 
Request: Send a blank email to php-notes+get-167705@lists.php.net to get a copy of this message
chunk_split() is not multibyte safe. If you ever run into needing the function that is multibyte safe, here you go: <?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 = 0; $new = ''; foreach ($array as $char) { if ($n < $len) $new .= $char; elseif ($n == $len) { $new .= $glue . $char; $n = 0; } $n++; } return $new; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 220.246.160.27 ---- Manual Page -- http://www.php.net/manual/en/function.chunk-split.php Edit -- https://master.php.net/note/edit/97156 Del: integrated -- https://master.php.net/note/delete/97156/integrated Del: useless -- https://master.php.net/note/delete/97156/useless Del: bad code -- https://master.php.net/note/delete/97156/bad+code Del: spam -- https://master.php.net/note/delete/97156/spam Del: non-english -- https://master.php.net/note/delete/97156/non-english Del: in docs -- https://master.php.net/note/delete/97156/in+docs Del: other reasons-- https://master.php.net/note/delete/97156 Reject -- https://master.php.net/note/reject/97156 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167705) next »