note 13357 added to function.wordwrap.php
| From: | lopi at supereva dot it | Date: | Wed, 13 Jun 2001 08:24:43 +0000 |
| Subject: | note 13357 added to function.wordwrap.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-14335@lists.php.net to get a copy of this message | ||
I've had problems using wordwrap, so I made this function which wraps the string at the given
lenght and puts the chunks in an array
function mywrap($str,$len,$arr) {
$slen=strlen($str);
for ( $i=0 ; $i<= (ceil($slen/$len)-1) ; $i++ ) {
$arr[$i]=substr($str,($len*$i),$len);
}
return $arr;
}
Example:
$cunks=mywrap("thereyougo!",2,$new);
print_r($chunks);
will return
Array ( [0] => th
[1] => er
[2] => ey
[3] => ou
[4] => go
[5] => !
)
..and there you go
http://www.php.net/manual/en/function.wordwrap.php