note 94452 added to function.wordwrap
| From: | andrnag at yandex dot ru | Date: | Fri, 06 Nov 2009 06:28:26 +0000 |
| Subject: | note 94452 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162433@lists.php.net to get a copy of this message | ||
This is a really working multibite wordwrap function. Teted on utf-8 English and Russian strings.
It's a compilation on other functions represented here.
<?php
function utf8_wordwrap($str, $width = 75, $break = "\n") // wordwrap() with utf-8
support
{
$str = preg_split('/([\x20\r\n\t]++|\xc2\xa0)/sSX', $str, -1,
PREG_SPLIT_NO_EMPTY);
$len = 0;
foreach ($str as $val)
{
$val .= ' ';
$tmp = mb_strlen($val, 'utf-8');
$len += $tmp;
if ($len >= $width)
{
$return .= $break . $val;
$len = $tmp;
}
else
$return .= $val;
}
return $return;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 89.189.177.161
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/94452
Del: integrated -- https://master.php.net/note/delete/94452/integrated
Del: useless -- https://master.php.net/note/delete/94452/useless
Del: bad code -- https://master.php.net/note/delete/94452/bad+code
Del: spam -- https://master.php.net/note/delete/94452/spam
Del: non-english -- https://master.php.net/note/delete/94452/non-english
Del: in docs -- https://master.php.net/note/delete/94452/in+docs
Del: other reasons-- https://master.php.net/note/delete/94452
Reject -- https://master.php.net/note/reject/94452
Search -- https://master.php.net/manage/user-notes.php