Based on the @rray response
$separado = implode(' ', str_split('9999999999999999', 4));
If I wanted to score:
$separado = implode('.', str_split('9999999999999999', 4));
As explained above, the split
splits the string into equal parts. Additionally the implode
"glue" the separate pieces, using a string at your choice among them.
If extra space at the end is not a problem, see more elegant alternative with chunk_split
in the reply mentioned.
If the number of digits varies and you want something like
99 9999 9999
can use this alternative:
for($i=strlen($string); $i>0; $i-=4) $string=substr_replace($string, ' ', $i, 0);
It inserts the "end to start" spaces. See working on IDEONE.
I don’t quite understand.
– Wolf Prog.
The purpose of this function is to break them, correct? str_split('9999999999999', 4); Mas and the function of picking the distributed number? Just like you said. $num1 = "9999"; //part 1 $num2 = "9999"; /part 2 $num3 = "9999"; //part 3 $num4 = "9999"; /part 4
– Wolf Prog.
@Wolfprog. do you want to add or split the number? or just add spaces every 4 characters?
– rray
See the documentation for str_split(), it is very interactive... but this function even that will help you solve your problem... it will turn your number into "arrays"
– Thiago Cunha
Darley, below, already solved my problem. But it still helped a lot in the ethics of the resolution.
– Wolf Prog.
You’ll split the numbers and print them in any way you want on the front end... if you want to play it that way in the database... you’ll have to add an empty space between the numbers... This is actually a good thing to do in javascript, it’s more of a front-end taskend... if your doubt is the same... print on the screen!
– Thiago Cunha