I am working in my php function. My requirement is to convert :
1,234
into
1234
I know it can be achieved by str_replace but is any inbuilt PHP function exists for this or not.
I am working in my php function. My requirement is to convert :
1,234
into
1234
I know it can be achieved by str_replace but is any inbuilt PHP function exists for this or not.
You could use http://php.net/number_format as such:
number_format(1.234,3,'','');
and this will output:
1234
In addition, you could see this post PHP: get number of decimal digits to get a good idea on how to automate the second parameter of the above function.
str_replace is not bad to do this. BTW, there is a multiple alternatives. You could use one of the from below:
$a = '1,234';
$a = preg_replace('/[.,]/', '', $a);
Regular expression for simple character substitution is overkill.
2 strstr
$a = '1,234';
$b = strtr($a, array('.' => '', ',' => ''));
You'd be better off using strstr. Above both example will help you.