Cannot work out a php str_replace() to remove comma

KiloJKilo picture KiloJKilo · Jul 17, 2012 · Viewed 16.7k times · Source

In a PHP project, I have:

$string = "1,555";

str_replace(',', '', $string);
echo $string; //is still 1,555

str_replace does not remove the comma. If I var_dump. I get string(5) "1,555"

Any ideas? I just simply need to remove the commas so I can compute.

Answer

Yan Berk picture Yan Berk · Jul 17, 2012
$string = str_replace(',', '', $string);