Voting

: eight minus seven?
(Example: nine)

The Note You're Voting On

secretr at NOSPAM dot e107 dot org
14 years ago
setlocale() and floatval() duo could break your DB queries in a very simple way:

<?php
setlocale
(LC_ALL, 'bg_BG', 'bgr_BGR');
echo
floatval(0.15); // output 0,15
?>

You would need simple workaround like:

<?php
function number2db($value)
{
$larr = localeconv();
$search = array(
$larr['decimal_point'],
$larr['mon_decimal_point'],
$larr['thousands_sep'],
$larr['mon_thousands_sep'],
$larr['currency_symbol'],
$larr['int_curr_symbol']
);
$replace = array('.', '.', '', '', '', '');

return
str_replace($search, $replace, $value);
}

setlocale(LC_ALL, 'bg_BG', 'bgr_BGR');
$testVal = floatval(0.15); // result 0,15
var_dump($testVal, number2db($testVal));

// Result:
// float(0,15)
// string(4) "0.15"
?>

<< Back to user notes page

To Top