note 41816 added to function.str-split
| From: | josh at josherickson dot org | Date: | Thu, 22 Apr 2004 20:59:24 +0000 |
| Subject: | note 41816 added to function.str-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68555@lists.php.net to get a copy of this message | ||
I needed a function that split a string by words so I could insert it into an image.
<?php
function word_split($str,$max_len)
{
$str_2 = explode(" ", $str);
$i[0] = 0;
$return_a.= "";
$return_b.= "";
foreach($str_2 as $a)
{
if(strlen($return_a) < $max_len)
{
$return_a.= $a." ";
$return_b[$i[0]] = $return_a;
}
if(strlen($return_a) > $max_len) {
$return_a = FALSE;
$i[0]++;
}
}
return $return_b;
}
?>
$max_len, is of course the maximum string length.
$str, is the string.
----
Manual Page -- http://www.php.net/manual/en/function.str-split.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41816
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41816&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41816&report=yes
Search -- http://master.php.net/manage/user-notes.php