note 89369 added to function.wordwrap
| From: | Matt at newbiewebdevelopment dot idk | Date: | Wed, 04 Mar 2009 21:53:17 +0000 |
| Subject: | note 89369 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151488@lists.php.net to get a copy of this message | ||
My version of multibyte wordwrap
<?php
function mb_wordwrap($string, $width=75, $break="\n", $cut = false) {
if (!$cut) {
$regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.',}\b#U';
} else {
$regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.'}#';
}
$string_length = mb_strlen($string,'UTF-8');
$cut_length = ceil($string_length / $width);
$i = 1;
$return = '';
while ($i < $cut_length) {
preg_match($regexp, $string,$matches);
$new_string = $matches[0];
$return .= $new_string.$break;
$string = substr($string, strlen($new_string));
$i++;
}
return $return.$string;
}
$mb_string = "ããã«ã¡ã¯";//Hello in Japanese
$cut_mb_string = mb_wordwrap($mb_string,1," ",true); //ã ã ã« ã¡ ã¯
print($cut_mb_string);
?>
----
Server IP: 208.69.120.35
Probable Submitter: 207.255.115.174
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/89369
Del: integrated -- https://master.php.net/note/delete/89369/integrated
Del: useless -- https://master.php.net/note/delete/89369/useless
Del: bad code -- https://master.php.net/note/delete/89369/bad+code
Del: spam -- https://master.php.net/note/delete/89369/spam
Del: non-english -- https://master.php.net/note/delete/89369/non-english
Del: in docs -- https://master.php.net/note/delete/89369/in+docs
Del: other reasons-- https://master.php.net/note/delete/89369
Reject -- https://master.php.net/note/reject/89369
Search -- https://master.php.net/manage/user-notes.php