note 41816 deleted from function.str-split by aidan
| From: | aidan@php.net | Date: | Tue, 01 Jun 2004 06:17:49 +0000 |
| Subject: | note 41816 deleted from function.str-split by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70383@lists.php.net to get a copy of this message | ||
Note Submitter: josh@josherickson.org
----
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.