www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Price PCRE

  1. #1
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239

    resolved [RESOLVED] Price PCRE

    I need a solid regx for the below inputs/outputs.

    £165,454.34 = 165454.34
    £23,934 = 23934
    £blah = 0
    £23 pounds = 23
    £23.39.39 = 23.39

    Cheers
    Last edited by MrCoder; 01-09-2007 at 06:21 AM.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,400
    PHP Code:
    <?php
    $testData 
    = array(
       
    '£165,454.34',
       
    '£23,934',
       
    '£blah',
       
    '£23 pounds',
       
    '£23.39.39'
    );
    foreach(
    $testData as $input)
    {
       
    $output round(preg_replace('/[^\d.]/'''$input), 2);
       echo 
    "<p>$output</p>\n";
    }
    ?>
    NOTE: this won't care if the input starts with a "£", "$", or no currency symbol.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    Cheers mate, I didnt even think about using round() or number_format().

    I should sit back and think more offen lol!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles