If you need the chunks to be split from the right, you can use the following function:
<? function chunk_split_right($str,$len=3,$delim=',') {
$size = strlen($str);
if( $size <= $len ) return $str;
return (chunk_split_right(substr($str,0,$size-$len),$len,$delim).
$delim.substr($str,$size-$len,$len));
}
?>
This is useful for formating large numbers into human readable strings, e.g.
<? echo chunk_split_right(1234567890); ?>
=> 1,234,567,890
