note 78352 added to function.wordwrap
| From: | golanzakaiATpatternDOTcoDOTil at osu1 dot php dot net | Date: | Mon, 08 Oct 2007 05:39:09 +0000 |
| Subject: | note 78352 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131219@lists.php.net to get a copy of this message | ||
/**
* Wordwrap without unnecessary word splitting using multibyte string functions
*
* @param string $str
* @param int $width
* @param string $break
* @return string
* @author Golan Zakai <golanzakaiATpatternDOTcoDOTil>
*/
function _wordwrap( $str, $width, $break ) {
$formatted = '';
$position = -1;
$prev_position = 0;
$last_line = -1;
/// looping the string stop at each space
while( $position = mb_stripos( $str, " ", ++$position, 'utf-8' ) ) {
if( $position > $last_line + $width + 1 ) {
$formatted.= mb_substr( $str, $last_line + 1, $prev_position - $last_line - 1,
'utf-8' ).$break;
$last_line = $prev_position;
}
$prev_position = $position;
}
/// adding last line without the break
$formatted.= mb_substr( $str, $last_line + 1, mb_strlen( $str ), 'utf-8' );
return $formatted;
}
----
Server IP: 212.199.163.191
Probable Submitter: 80.178.120.155
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/78352
Del: integrated -- https://master.php.net/note/delete/78352/integrated
Del: useless -- https://master.php.net/note/delete/78352/useless
Del: bad code -- https://master.php.net/note/delete/78352/bad+code
Del: spam -- https://master.php.net/note/delete/78352/spam
Del: non-english -- https://master.php.net/note/delete/78352/non-english
Del: in docs -- https://master.php.net/note/delete/78352/in+docs
Del: other reasons-- https://master.php.net/note/delete/78352
Reject -- https://master.php.net/note/reject/78352
Search -- https://master.php.net/manage/user-notes.php