Returns the numeric value of a string in PHP

advertisements

How can I get the numeric value from an string? In my case string is R1350.00 and

Expected output:

1350

I tried the following:

$result = preg_replace("/[^a-zA-Z0-9]+/", "", 'R1350.00');

but I also want to remove the last two string 00. It is an amount value in ZAR. and I have to store the integer value in my database.


You can use str_replace function and then number_format

$str = 'R1350.00';
$str = str_replace('R',''.$str);
$str = number_format($str,0,'','');
echo $str;
//output 1350