I'm trying to replicate PHP5's str_split function in PHP 4, adapting some coding I found in the manual which seems straightforward. I want the string split into groups of 3 letters and then output as ATG GTG AGC, etc.
Get the msg:
Warning: Invalid argument supplied for foreach()
What am I missing?
__
$string = "ATGGTGAGCAAGGGCGAGGAGCTGTTCACCGGGGTGGTGCCCATCCTGGTCGAGCTGGAC
GGCGACGTAAACGGCCACAAGTTCAGCGTGTCCGGCGAGGGCGAGGGCGATGCCACCTAC
GGCAAGCTGACCCTGAAGTTCATCTGCACCACCGGCAAGCTGCCCGTGCCCTGGCCCACC
";
$split_length = 3;
if(!function_exists('str_split')){
function str_split($string,$split_length){
$cnt = strlen($string);
for ($i=0; $i < $cnt; $i += $split_length)
$chunks[]= substr($str,$i,$split_length);
return $chunks;
}
}
$chunks = str_split($string,$split_length);
foreach ($chunks as $chunk) {
echo $chunk . " ";
}