hi, i have a number with 9 digits lenght and i want split this number: 922888222 into this: 922 888 222 how can i do that? thanks a lot for your help
<? $str="922888222"; $str1=substr($str, 0, 3); $str2= substr($str, 3, 3); $str3= substr($str, 6, 3); echo str1; echo str2; echo str3; ?> I hope it helps Regards Alex
There is also a built-in PHP function that does it $string = "922888222"; $split = str_split($string, 3); /* $split[0] = "922"; $split[1] = "888"; $split[2] = "222"; */ PHP:
Both codes will work but i will prefer the second one should be used because it will use lesser memory of the PHP processor.