Search code examples
phpdecimaleregi

PHP remove decimal from number string


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;

Solution

  • $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.