PHP - Filter Non Numerals from a string -


i have variable:

$number 

that contain values in these formats:

125.00 125.00 $125.00 

i need insert number database, need remove/filter out isn't number whilst retaining decimals points.

not sure how/best approach in php?

use regex :

<?php $num = "125.00"; $num = preg_replace("/([^0-9\.,])/","",$num); $num = (double) $num; // make double allow point , comma $num = (int) $num; // , convert integer echo $num; ?> 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -