From: Andrei Zmievski Date: Thu, 16 Mar 2000 16:02:23 +0000 (+0000) Subject: @ Added is_numeric() that returns true if the argument is a number X-Git-Tag: PHP-4.0-RC1~115 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ddf3740cf97e93cad62b6a1f1063852cd49fb529;p=php @ Added is_numeric() that returns true if the argument is a number @ or a numeric string. (Andrei) --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 249512f563..6ae12fb939 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -270,6 +270,7 @@ function_entry basic_functions[] = { PHP_FALIAS(is_float, is_double, first_arg_allow_ref) PHP_FE(is_double, first_arg_allow_ref) PHP_FALIAS(is_real, is_double, first_arg_allow_ref) + PHP_FE(is_numeric, NULL) PHP_FE(is_string, first_arg_allow_ref) PHP_FE(is_array, first_arg_allow_ref) PHP_FE(is_object, first_arg_allow_ref) @@ -1126,6 +1127,38 @@ PHP_FUNCTION(is_object) php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_OBJECT); } +/* {{{ proto bool is_numeric(mixed value) + Returns true if value is a number or a numeric string */ +PHP_FUNCTION(is_numeric) +{ + zval **arg; + int result; + + if (ARG_COUNT(ht) !=1 || zend_get_parameters_ex(1, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + + switch ((*arg)->type) { + case IS_LONG: + case IS_DOUBLE: + RETURN_TRUE; + break; + + case IS_STRING: + result = is_numeric_string((*arg)->value.str.val, (*arg)->value.str.len, NULL, NULL); + if (result == IS_LONG || result == IS_DOUBLE) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } + break; + + default: + RETURN_FALSE; + break; + } +} +/* }}} */ /* 1st arg = error message diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index b17d27d526..db784df0a3 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -77,6 +77,7 @@ PHP_FUNCTION(is_resource); PHP_FUNCTION(is_bool); PHP_FUNCTION(is_long); PHP_FUNCTION(is_double); +PHP_FUNCTION(is_numeric); PHP_FUNCTION(is_string); PHP_FUNCTION(is_array); PHP_FUNCTION(is_object);