How to get rid of the dollar sign?

Ok, so I am importing csv through the PHP script that I am writing, and the spreadsheet has values ​​like $ 4090.00, and I need to paste these values ​​into the mysql decimal field using PHP. Is there an easy way to get rid of $ if it is present in PHP

+3
source share
4 answers

With str_replace or even cropping:

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

There are many solutions for this. Also note that you should use the period separator for decimal and integer parts, not a comma.

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

, str_replace :

$nodollars = str_replace('$', '', $some_string);
+3
0

Source: https://habr.com/ru/post/1773499/


All Articles