1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to remove a currency sign

Discussion in 'PHP' started by petjelly, Jun 9, 2008.

  1. #1
    Hi,

    I HAVE A variable like

    Total = $40
    Total = €40
    Total = GBP 40

    How do i remove or concatenate these signs so that total = 40

    Regards
     
    petjelly, Jun 9, 2008 IP
  2. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <?php 
      $total = "ABC 40 XYZ";
      $total= eregi_replace('[^0-9]','',$total);
      echo $total;  //prints 40
    ?>
    
    PHP:
     
    selling vcc, Jun 9, 2008 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    I would use preg_replace instead of ereg_replace. The ereg_ functions are going to be removed in the next version of php (php6) so it's probably a good idea to stop using them now.

    Also, you may want to allow a ' . ' in case you have a decimal number.
     
    jestep, Jun 10, 2008 IP