function parseInt($string) { // return intval($string); if(preg_match('/(\d+)/', $string, $array)) { return $array[1]; } else { return 0; } }
echo parseInt("2008"); // 2008 echo parseInt("99.90 dollars"); // 99 echo parseInt("www.w3.org"); // 3 echo parseInt("300 spartiates"); // 300 echo parseInt("block text..."); // 0
Source: AB-D Création de sites internet
// return intval($string);
if(preg_match('/(\d+)/', $string, $array)) {
return $array[1];
} else {
return false;//I think that this is better!!
}
}