Regex preg_match issue with commas

Posted by Serge Sf on Stack Overflow See other posts from Stack Overflow or by Serge Sf
Published on 2013-10-21T02:11:20Z Indexed on 2013/10/21 3:54 UTC
Read the original article Hit count: 128

Filed under:
|
|
|

This is my code to pre_match when an amount looks like this: $ 99.00 and it works

if (preg_match_all('/[$]\s\d+(\.\d+)?/', $tout, $matches))
{ $tot2 = $matches[0];
$tot2 = preg_replace("/\\\$/", '', $tot2);}

I need to do the same thing for a amount that looks like this (with a comma): $ 99,00

Thank you for your help (changing dot for comma do not help, there is an "escape" thing I do not understand...

Idealy I need to preg_match any number that looks like an amount with dot or commas and with or without dollar sign before or after (I know, it's a lot to ask :) since on the result form I want to scan there are phone and street numbers...

UPDATE (For some reason I cannot comment on replies) : To test properly, I need to preg_replace the comma by a dot (since we are dealings with sums, I don't think calculations can be done on numbers with commas in it).

So to clarify my question, I should say : I need to transform, let's say "$ 200,24" to "200.24". (could be amounts bettween 0.10 to 1000.99) :

    $tot2 = preg_replace("/\\\$/", '', $tot2);}

(this code just deals with the $ (it works), I need adaptation to deal also with the change of (,) for (.))

© Stack Overflow or respective owner

Related posts about php

Related posts about regex