note 65981 added to function.wordwrap
| From: | PaoloStefan at osu1 dot php dot net | Date: | Thu, 11 May 2006 11:13:03 +0000 |
| Subject: | note 65981 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111120@lists.php.net to get a copy of this message | ||
Hi everyone,
I have modified textWrap(); this one works just fine (the last one had a buggy regular expression!)
and also gives you the chance to choose the line separator (3rd param).
Enjoy :)
<?php
function textWrap($text, $size, $separator="\\r\\n" ) {
$new_text = '';
$text_1 = explode('>',$text);
$sizeof = sizeof($text_1);
$remain = $size;
for ($i=0; $i<$sizeof; ++$i) {
$text_2 = explode('<',$text_1[$i]);
if (!empty($text_2[0])){
$perl = '/([^\\n\\r .]{'. $remain .',})/i';
$possibly_splitted= preg_replace( $perl, '$1'.$separator, $text_2[0] );
$splitted = explode($separator,$possibly_splitted);
$remain -= strlen($splitted[0]);
if($remain<=0) $remain = $size;
$new_text .= $possibly_splitted;
}
if (!empty($text_2[1])) $new_text .= '<' . $text_2[1] . '>';
}
return $new_text;
}
?>
----
Server IP: 213.92.11.19
Probable Submitter: 217.133.10.137
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- http://master.php.net/note/edit/65981
Del: integrated -- http://master.php.net/note/delete/65981/integrated
Del: useless -- http://master.php.net/note/delete/65981/useless
Del: bad code -- http://master.php.net/note/delete/65981/bad+code
Del: spam -- http://master.php.net/note/delete/65981/spam
Del: non-english -- http://master.php.net/note/delete/65981/non-english
Del: in docs -- http://master.php.net/note/delete/65981/in+docs
Del: other reasons-- http://master.php.net/note/delete/65981
Reject -- http://master.php.net/note/reject/65981
Search -- http://master.php.net/manage/user-notes.php