PHP remove decimal from number string

DonJuma picture DonJuma · Jan 19, 2011 · Viewed 18.3k times · Source

i have an algorithym that gives back a number with a decimal point (I.E. ".57"). What I would like to do is just get the "57" without the decimal.

I have used eregi_replace and str_replace and neither worked!

$one = ".57";
$two = eregi_replace(".", "", $one);
print $two;

Answer

Jonah picture Jonah · Jan 19, 2011
$one = '.57';
$two = str_replace('.', '', $one);
echo $two;

That works. 100% tested. BTW, all ereg(i)_* functions are depreciated. Use preg_* instead if you need regex.