utiliser ereg_replace
$string = "$100,000";
$int = ereg_replace("[^0-9]", "", $string);
echo $int;
extrants
1000000
function toInt($str)
{
return (int)preg_replace("/\..+$/i", "", preg_replace("/[^0-9\.]/i", "", $str));
}
Mise à jour
<?php
$string = array("$1,000,000.00","$1 000 000.00","1,000 000.00","$123","$123 456 789","0.15¢");
foreach($string as $s) {
echo $s . " = " . toInt($s) . "\n";
}
function toInt($str)
{
return preg_replace("/([^0-9\\.])/i", "", $str);
}
?>
Extrants
$1,000,000.00 = 1000000.00
$1 000 000.00 = 1000000.00
1,000 000.00 = 1000000.00
$123 = 123
$123 456 789 = 123456789
0.15¢ = 0.15
et si vous le lancez comme un entier
<?php
$string = array("$1,000,000.00","$1 000 000.00","1,000 000.00","$123","$123 456 789","0.15¢");
foreach($string as $s) {
echo $s . " = " . _toInt($s) . "\n";
}
function _toInt($str)
{
return (int)preg_replace("/([^0-9\\.])/i", "", $str);
}
?>
extrants
$1,000,000.00 = 1000000
$1 000 000.00 = 1000000
1,000 000.00 = 1000000
$123 = 123
$123 456 789 = 123456789
0.15¢ = 0
Donc, vous l'avez. une seule ligne, un remplacement. vous êtes prêt à y aller.