]> granicus.if.org Git - php/commitdiff
@ Added is_numeric() that returns true if the argument is a number
authorAndrei Zmievski <andrei@php.net>
Thu, 16 Mar 2000 16:02:23 +0000 (16:02 +0000)
committerAndrei Zmievski <andrei@php.net>
Thu, 16 Mar 2000 16:02:23 +0000 (16:02 +0000)
@ or a numeric string. (Andrei)

ext/standard/basic_functions.c
ext/standard/basic_functions.h

index 249512f563fe505f665f10383a9e4b6c0c5dddde..6ae12fb939be9afaea0007d124579888fe43afba 100644 (file)
@@ -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
index b17d27d526bfa6b9ed75468883504c69677fbd29..db784df0a32844dcce3b7164c848c0499415d4ea 100644 (file)
@@ -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);