Sanizite filter user input semicolon comma / dot

Trying to figure out how user filters php in a smart way

//Do sanization of user input
//$_POST['amount_ecb'] can be 77,7 or 77.7

$amount = filter_input(INPUT_POST, 'amount_ecb', 
FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); 

if the displayed value is 77.7, it sets the amount correctly, but if the user dials a semicolon instead of a period (for example, 77.7) $amountreturns 77

I want him to return 77.7 in both cases. Can this be solved using filters?

UPDATE After feedback (sent reply), I still have the same problem:

Using

$_POST['amount_ecb'] = str_replace(',', '.', $_POST['amount_ecb']);

before

It was he who returned

$ _ POST Object

array (size=5)
  'amount_ecb' => string '77.7' (length=4)
  'from_ecb' => string 'GBP' (length=3)
  'to_ecb' => string 'SEK' (length=3)
  'submit' => string 'Calculate currency' (length=18)
  'result_decimals' => string '4' (length=1)

$ amount

string '777' (length=3)
+4
source share
2 answers

- , ! ( , - input_filter).

- ...

$amount_ecb = str_replace(',', '.', $_POST['amount_ecb']);
$amount = filter_var($amount_ecb, 
FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); 

($amount_ecb), , filter_var $amount_ecb - filter_input .

+1
/* find , and replace with . if any; */
$_GET['search'] = str_replace(',', '.', $_GET['search']);

/* finally filter data */
$amount = filter_var($_GET['search'], FILTER_SANITIZE_NUMBER_FLOAT, array(
  'flags'=>FILTER_FLAG_ALLOW_FRACTION));
0

All Articles