#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    227
    Rep Power
    17

    Preg_replace to turn $12\\\\\\.50 = $12.50


    Hi

    Can anyone show me the correct preg_replace regular expression to match "\\\\\\." with 1 or more digits on either side?

    my current version below cuts off whatever digit is directly to the left of the "." for some reason - ie. it turns 15\\\\\\.50 into 1.50

    Code:
    		$string = preg_replace("/[0-9](\\\{6}\.)[0-9]/",".",$string);
    Regan
  2. #2
  3. Psycho Canadian
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jan 2001
    Location
    Canada
    Posts
    4,846
    Rep Power
    635
    Try this
    PHP Code:
    $string '15\\\\\\.50';
    $string preg_replace("/([0-9]+)\\\+\.([0-9]+)/""$1.$2"$string); 
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    227
    Rep Power
    17
    Originally Posted by Viper_SB
    PHP Code:
    $string '15\\\\\\.50';
    $string preg_replace("/([0-9]+)\\\+\.([0-9]+)/""$1.$2"$string); 

    Nope, that deletes the digits on both sides. :|

    I just want to "replace" the "\\\\\\." with "." if it has a digit on both sides of it.
  6. #4
  7. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    Originally Posted by ryel01
    Nope, that deletes the digits on both sides. :|
    I just tried it and it works fine.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    227
    Rep Power
    17
    Originally Posted by requinix
    I just tried it and it works fine.
    Ahh you're right, sorry I missed the "$1.$2" when pasting it into my page.

    WORKS PERFECTLY!!!

    Thanks requinix!
  10. #6
  11. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    Originally Posted by ryel01
    Thanks requinix!
    Me? Thank Viper, all I did was check that it worked.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    227
    Rep Power
    17
    Ah, it's been a long day and night.

    Thanks Viper_SB!




    Regan

IMN logo majestic logo threadwatch logo seochat tools logo