note 90694 deleted from function.wordwrap by danbrown

From: Date: Wed, 05 May 2010 14:19:22 +0000
Subject: note 90694 deleted from function.wordwrap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168972@lists.php.net to get a copy of this message
Note Submitter: php dot net at henrik dot synth dot no ---- 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); ?>

« previous php.notes (#168972) next »