Isis
Isis

Reputation: 4666

PHP, substr symbols from the end

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

Answers (4)

Pascal MARTIN
Pascal MARTIN

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

GSto
GSto

Reputation: 42350

number_format('2352362361',0,'',' ')

note that argument 3 is empty, where argument 4 is a space

Upvotes: 1

code-zoop
code-zoop

Reputation: 7368

Try number_format

Upvotes: 1

djc
djc

Reputation: 11731

number_format($num, 0, '.', ' ');

Upvotes: 1

Related Questions