I was wondering if anyone could help me with a function that strips all the digits from a string and returns them. Something like this:
Code: Select all
$input = "(04) 854 00912";
echo getDigit($input);
// Would print 0485400912Moderator: General Moderators
Code: Select all
$input = "(04) 854 00912";
echo getDigit($input);
// Would print 0485400912Code: Select all
/*
REMOVE ANY NON 0-9 CHAR
IF RETURN_INT IS TRUE
RETURN THE INT VALUE
SO 2A.3 WOULD RETURN 2
*/
function removeAllNonNumericChar($num,$return_int){
$num = preg_replace('#[^\d\.]#','',$num);
if($return_int && !ctype_digit($num) && strpos($num,'.') > 0){
$num = substr($num."",0,strpos($num,'.'));
}
return $num;
}