note 53520 deleted from function.str-split by aidan
| From: | aidan@php.net | Date: | Sat, 04 Feb 2006 07:14:45 +0000 |
| Subject: | note 53520 deleted from function.str-split by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-102969@lists.php.net to get a copy of this message | ||
Note Submitter: Lepidosteus
----
katoda's function seems to loose part of the string while splitting.
i.e a md5 string splitted into 4 chars lenght strings will lost half its content (32 chars => 16
chars).
Here's a working one (made by nic58) :
<?php
function split_str($str, $num = 1)
{
$arr = array();
for($i = 0, $len = strlen($str), $j = -1; $i < $len; $i++)
{
if(($i % $num) == 0)
{
$j++;
}
$arr[$j] .= $str[$i];
}
return $arr;
}
?>