Brain Fart

Discussion in 'PHP' started by bizoppz, Dec 6, 2006.

  1. #1
    I know this, I really do, but I am having a brain fart I guess...

    I have a php script which outputs the value of a certain (numeric) field. This field is updated regularly and automatically.

    When the info is echo'd to the screen, I want the numeric output to show its value with the appropriate comma in place

    Example: number = 1234567890
    Should show as = 1,234,567,890

    Within my MySQL fetch array, I have:

    $number = $row['number'];

    What should it be to add the comma after every 3rd number? I know it is a preg_replace, but again, brain fart...
     
    bizoppz, Dec 6, 2006 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    $number = number_format($row['number'],'', '', ',');
     
    krakjoe, Dec 6, 2006 IP
  3. bizoppz

    bizoppz Peon

    Messages:
    1,889
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    0
    #3
    2 seconds after I posted, I realized it. Thanks a bunch.
     
    bizoppz, Dec 6, 2006 IP