note 29218 deleted from function.substr by aidan
| From: | aidan@php.net | Date: | Sat, 03 Jul 2004 07:46:50 +0000 |
| Subject: | note 29218 deleted from function.substr by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72373@lists.php.net to get a copy of this message | ||
Note Submitter: buonstefano@inwind.it
----
Still another fx to split string into token with 'token length', 'separator' and
'replace' string customizable:
function CutStr($string, $length, $separator=" ", $replace="\n") {
$tmp = explode($separator, $string);
$result = "";
$tokencnt = 1;
while (list($foo, $value) = each($tmp)) {
if (strlen($result.$value) < ($length * $tokencnt)) {
$result.=$separator.$value;
} else {
$result.=$replace.$value;
$tokencnt++;
}
}
return $result;
}