PHP: Insert a gap every N symbol but from the end
-
How to insert a gap on the RR every N symbol, but starting from the start of the line to the end. Like,
1234567
- Yes.1 234 567
(if every three symbols).chunk_split
andwordwrap
only with more than 0 valuesIn principle, this is how:
$reverse = strrev("1234567"); $withSpaces = chunk_split($reverse, 3, ' '); echo strrev($withSpaces);
But maybe something's easier.
-
http://php.net/manual/ru/function.number-format.php
If briefly:
- Introduction
- How many symbols after the tip.
- Glass sectioner.
- Dividing thousands (every third end)
Example:
echo number_format(1000000, 0, '.', ' '); // 1 000 000
echo number_format(1000000, 2, '.', ','); // 1,000,000.00