note 109358 added to function.chunk-split
| From: | zeusgerde at arcor dot de | Date: | Tue, 10 Jul 2012 07:14:51 +0000 |
| Subject: | note 109358 added to function.chunk-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-189085@lists.php.net to get a copy of this message | ||
Three-liner for multibyte version of chunk_split()
<?php
function mb_chunk_split($body, $chunklen = 76, $end = "\r\n") {
return join($end, preg_split('/(.{'. $chunklen .'})/us', $body, 0,
PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE));
}
?>
preg_split() splits the string into $chunklen pieces
join() glues everything together to one string
PCRE_UTF8 makes it a multibyte version
PCRE_DOTALL makes sure that line breaks are also captured
PREG_SPLIT_NO_EMPTY removes the empty lines that were captured by the regular expression
PREG_SPLIT_DELIM_CAPTURE re-adds the non-empty lines that were captured by the regular expression
(first sub-pattern)
----
Server IP: 212.124.37.9
Probable Submitter: 217.91.9.192
----
Manual Page -- http://www.php.net/manual/en/function.chunk-split.php
Edit -- https://master.php.net/note/edit/109358
Del: integrated -- https://master.php.net/note/delete/109358/integrated
Del: useless -- https://master.php.net/note/delete/109358/useless
Del: bad code -- https://master.php.net/note/delete/109358/bad+code
Del: spam -- https://master.php.net/note/delete/109358/spam
Del: non-english -- https://master.php.net/note/delete/109358/non-english
Del: in docs -- https://master.php.net/note/delete/109358/in+docs
Del: other reasons-- https://master.php.net/note/delete/109358
Reject -- https://master.php.net/note/reject/109358
Search -- https://master.php.net/manage/user-notes.php