note 118887 added to function.chunk-split
| From: | vijit at mail dot ru | Date: | Tue, 23 Feb 2016 06:22:59 +0000 |
| Subject: | note 118887 added to function.chunk-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205016@lists.php.net to get a copy of this message | ||
As an alternative for qeremy [atta] gmail [dotta] com
There is much shorter way for binarysafe chunking of multibyte string:
<?php
function word_chunk($str, $len = 76, $end = "\n") {
$pattern = '~.{1,' . $len . '}~u'; // like "~.{1,76}~u"
$str = preg_replace($pattern, '$0' . $end, $str);
return rtrim($str, $end);
}
$str = 'ÑÑÑÑкий';
echo chunk_split($str, 3) ."\n";
echo word_chunk($str, 3) . "\n";
?>
�
�Ñ
�
�и
й
ÑÑÑ
Ñки
й
----
Server IP: 72.52.91.14
Probable Submitter: 5.136.87.208
----
Manual Page -- http://php.net/manual/en/function.chunk-split.php
Edit -- https://master.php.net/note/edit/118887
Del: integrated -- https://master.php.net/note/delete/118887/integrated
Del: useless -- https://master.php.net/note/delete/118887/useless
Del: bad code -- https://master.php.net/note/delete/118887/bad+code
Del: spam -- https://master.php.net/note/delete/118887/spam
Del: non-english -- https://master.php.net/note/delete/118887/non-english
Del: in docs -- https://master.php.net/note/delete/118887/in+docs
Del: other reasons-- https://master.php.net/note/delete/118887
Reject -- https://master.php.net/note/reject/118887
Search -- https://master.php.net/manage/user-notes.php