Reputation: 4666
There are number '2352362361 ', as it is separated by spaces from the end of 3 characters? The output should obtain '2 352 362 361 '
Upvotes: 1
Views: 194
Reputation: 401142
If you have that number as a string :
$str = '2352362361 ';
You can first convert that string to an integer, using intval
:
$int = intval($str);
And, then, use number_format
on that integer :
echo number_format($int, 0, '.', ' ');
And you get :
2 352 362 361
(If the space at the end was intentional, you can add it back if necessary)
And number_format
will also work even if you pass it the string without converting it to an integer first :
$str = '2352362361 ';
echo number_format($str, 0, '.', ' ');
Upvotes: 2
Reputation: 42350
number_format('2352362361',0,'',' ')
note that argument 3 is empty, where argument 4 is a space
Upvotes: 1