note 78353 added to function.wordwrap
| From: | golanzakaiATpatternDOTcoDOTil at osu1 dot php dot net | Date: | Mon, 08 Oct 2007 05:42:50 +0000 |
| Subject: | note 78353 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131220@lists.php.net to get a copy of this message | ||
<?php
/**
* 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: 208.69.120.35
Probable Submitter: 80.178.120.155
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/78353
Del: integrated -- https://master.php.net/note/delete/78353/integrated
Del: useless -- https://master.php.net/note/delete/78353/useless
Del: bad code -- https://master.php.net/note/delete/78353/bad+code
Del: spam -- https://master.php.net/note/delete/78353/spam
Del: non-english -- https://master.php.net/note/delete/78353/non-english
Del: in docs -- https://master.php.net/note/delete/78353/in+docs
Del: other reasons-- https://master.php.net/note/delete/78353
Reject -- https://master.php.net/note/reject/78353
Search -- https://master.php.net/manage/user-notes.php