开发者

Getting rid of the dollar sign?

开发者 https://www.devze.com 2023-01-24 02:08 出处:网络
Ok so i am importing a csv via a PHP script I am writing and the spreadsheet has values like $4090,00 and i need to insert these values in a mysql decimal field using PHP. Is there an ea开发者_如何学G

Ok so i am importing a csv via a PHP script I am writing and the spreadsheet has values like $4090,00 and i need to insert these values in a mysql decimal field using PHP. Is there an ea开发者_如何学Gosy way to get rid of the $ if its present in PHP


With str_replace, or even trim :

$str = str_replace('$', '', $str);
$str = trim($str, '$'); // only delete $ at start or end of the string

There are many solutions for this. Also, please note you have to use the period separator for decimals and integer part, not a comma.


$value = "$4090,00";
$value = preg_replace('/[\$,]/', '', $value);


Sure, you can use str_replace for this:

$nodollars = str_replace('$', '', $some_string);


Use sscanf if the input has a rigid format.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号