note 36303 added to function.wordwrap
| From: | php-general at lists dot php dot net | Date: | Sat, 04 Oct 2003 10:22:18 +0000 |
| Subject: | note 36303 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57800@lists.php.net to get a copy of this message | ||
<?php
function new_textwrap ($String, $breaksAt = 78, $breakStr = "\n", $cut = 1 ,
$padStr="") {
/*
new_textwrap 1.0 <linker@toter-link.de>
Based on textwrap 1.0 by Brian Moon <brian@phorum.org>
http://px.sklar.com/code-pretty.html?code_id=370
tested with PHP 3.0.16 WIN
You can use it as ' wordwrap ' from PHP4
$String The string to be wrapped.
$breaksAt How many characters each line should be.
$breakStr What character should be used to cause a break.
$cut If the cut is set to 1, the string is always wrapped at the specified width.
$padStr Allows for the wrapped lines to be padded at the begining.
*/
$newString="";
$lines=explode($breakStr, $String);
$cnt=count($lines);
for($x=0;$x<$cnt;$x++){
if(strlen($lines[$x])>$breaksAt){
$str=$lines[$x];
while(strlen($str)>$breaksAt){
$find = 1 ;
// echo $str."\n" ;
$pos=strrpos(substr($str, 0, $breaksAt+1), " ");
if ($pos == false) {
If($cut) {
$pos = $breaksAt ;
$find = 0 ;
} else {
$pos= strpos($str, " ");
if ($pos == false)
break;
}
}
$newString.=$padStr.substr($str, 0, $pos).$breakStr;
$str=(substr($str, $pos + $find)); // or $str=trim(substr($str, $pos));
}
$newString.=$padStr.$str.$breakStr;
}
else{
$newString.=$padStr.$lines[$x].$breakStr;
}
}
return substr ($newString,0, -(strlen($breakStr)));
} // end new_textwrap()
?>
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36303
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36303&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36303&report=yes
Search Tool -- http://master.php.net/manage/user-notes.php