i have variable $var1 = "21,855.00"
. tried using preg_replace
, str_replace
not achieve looking for. wish echo 21855
. how can using php?
just taking note:
if literal string
like:
$var1 = '21,855.00'; // string(9) "21,855.00"
you can way:
$var1 = '21,855.00'; $var2 = filter_var(strtok($var1, '.'), filter_sanitize_number_int); echo $var2; // 21855
or regex:
$var1 = '21,855.00'; $var2 = (int) preg_replace('/(?<=\d),(?=\d{3}\b)/','', $var1); var_dump($var2); // int(21855)
Comments
Post a Comment