cvs: /php4/ext/standard basic_functions.c basic_functions.h

From: Date: Thu, 16 Mar 2000 16:02:53 +0000
Subject: cvs: /php4/ext/standard basic_functions.c basic_functions.h
Groups: php.version4 
Request: Send a blank email to php-version4+get-12247@lists.php.net to get a copy of this message
andrei Thu Mar 16 08:02:53 2000 EDT Modified files: /php4/ext/standard basic_functions.c basic_functions.h Log: @ Added is_numeric() that returns true if the argument is a number @ or a numeric string. (Andrei) Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.174 php4/ext/standard/basic_functions.c:1.175 --- php4/ext/standard/basic_functions.c:1.174 Tue Mar 7 04:28:06 2000 +++ php4/ext/standard/basic_functions.c Thu Mar 16 08:02:23 2000 @@ -270,6 +270,7 @@ 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_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: php4/ext/standard/basic_functions.h diff -u php4/ext/standard/basic_functions.h:1.50 php4/ext/standard/basic_functions.h:1.51 --- php4/ext/standard/basic_functions.h:1.50 Mon Mar 6 12:37:11 2000 +++ php4/ext/standard/basic_functions.h Thu Mar 16 08:02:23 2000 @@ -29,7 +29,7 @@ */ -/* $Id: basic_functions.h,v 1.50 2000/03/06 20:37:11 ssb Exp $ */ +/* $Id: basic_functions.h,v 1.51 2000/03/16 16:02:23 andrei Exp $ */ #ifndef _BASIC_FUNCTIONS_H #define _BASIC_FUNCTIONS_H @@ -77,6 +77,7 @@ 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);

« previous php.version4 (#12247) next »