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 and wordwrap only with more than 0 values

    In 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:

    1. Introduction
    2. How many symbols after the tip.
    3. Glass sectioner.
    4. Dividing thousands (every third end)

    Example:

    echo number_format(1000000, 0, '.', ' '); // 1 000 000
    

    echo number_format(1000000, 2, '.', ','); // 1,000,000.00


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2