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.
精彩评论