1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 14:46:56 +02:00

refactoring toNumber() into e_parse class

This commit is contained in:
Achim Ennenbach
2018-05-04 19:27:00 +02:00
parent 2a1a6d4118
commit d01a97816f
4 changed files with 50 additions and 62 deletions

View File

@@ -1307,7 +1307,7 @@ class e_db_mysql
// return str_replace($search, $replace, floatval($fieldValue));
return $this->_toNumber($fieldValue);
return e107::getParser()->toNumber($fieldValue);
break;
case 'null':
@@ -1367,7 +1367,7 @@ class e_db_mysql
// $replace = array('.', '.', '', '', '', '');
// return str_replace($search, $replace, floatval($fieldValue));
return $this->_toNumber($fieldValue);
return e107::getParser()->toNumber($fieldValue);
break;
case 'null':
@@ -1439,31 +1439,6 @@ class e_db_mysql
}
/**
* Convert a string to a number (int/float)
*
* @param string $value
* @return int|float
*/
function _toNumber($value)
{
// adapted from: https://secure.php.net/manual/en/function.floatval.php#114486
$dotPos = strrpos($value, '.');
$commaPos = strrpos($value, ',');
$sep = (($dotPos > $commaPos) && $dotPos) ? $dotPos :
((($commaPos > $dotPos) && $commaPos) ? $commaPos : false);
if (!$sep) {
return preg_replace("/[^-0-9]/", "", $value);
}
return (
preg_replace("/[^-0-9]/", "", substr($value, 0, $sep)) . '.' .
preg_replace("/[^0-9]/", "", substr($value, $sep+1, strlen($value)))
);
}
/**
* @DEPRECATED
Similar to db_Update(), but splits the variables and the 'WHERE' clause.