note 90694 added to function.wordwrap

From: Date: Tue, 05 May 2009 09:49:13 +0000
Subject: note 90694 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-154215@lists.php.net to get a copy of this message
Here's my multibyte word wrapper. It's simpler than the other implementations mentioned here, and supports an input character set. <?php function mb_wordwrap($str, $width = 75, $break = "\n", $cut = false, $charset = null) { if ($charset === null) $charset = mb_internal_encoding(); $pieces = split($break, $str); $result = array(); foreach ($pieces as $piece) { $current = $piece; while ($cut && mb_strlen($current) > $width) { $result[] = mb_substr($current, 0, $width, $charset); $current = mb_substr($current, $width, 2048, $charset); } $result[] = $current; } return implode($break, $result); } $mb_string = "こんにちは"; //Hello in Japanese $cut_mb_string = mb_wordwrap($mb_string, 1 ," ", true, "utf-8"); //こ ん に ち は print($cut_mb_string); ?> ---- Server IP: 128.39.198.38 Probable Submitter: 195.159.86.22 ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit -- https://master.php.net/note/edit/90694 Del: integrated -- https://master.php.net/note/delete/90694/integrated Del: useless -- https://master.php.net/note/delete/90694/useless Del: bad code -- https://master.php.net/note/delete/90694/bad+code Del: spam -- https://master.php.net/note/delete/90694/spam Del: non-english -- https://master.php.net/note/delete/90694/non-english Del: in docs -- https://master.php.net/note/delete/90694/in+docs Del: other reasons-- https://master.php.net/note/delete/90694 Reject -- https://master.php.net/note/reject/90694 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#154215) next »