note 97158 added to function.chunk-split
| From: | Peterfromdezzignz dot com at osu1 dot php dot net | Date: | Mon, 05 Apr 2010 13:07:06 +0000 |
| Subject: | note 97158 added to function.chunk-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167708@lists.php.net to get a copy of this message | ||
Oops. Here is a correction for the post below.
<?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;
}
// DEMO:
$str = 'ä¸äºä¸äºä¸äºä¸äºä¸äº';
echo mb_chunk_split($str, 2, '*<br />');
// produces this output:
ä¸äº*
ä¸äº*
ä¸äº*
ä¸äº*
ä¸äº
?>
----
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/97158
Del: integrated -- https://master.php.net/note/delete/97158/integrated
Del: useless -- https://master.php.net/note/delete/97158/useless
Del: bad code -- https://master.php.net/note/delete/97158/bad+code
Del: spam -- https://master.php.net/note/delete/97158/spam
Del: non-english -- https://master.php.net/note/delete/97158/non-english
Del: in docs -- https://master.php.net/note/delete/97158/in+docs
Del: other reasons-- https://master.php.net/note/delete/97158
Reject -- https://master.php.net/note/reject/97158
Search -- https://master.php.net/manage/user-notes.php