Re: Fallo is_int()
| From: | Killer Dog | Date: | Wed, 31 Jan 2007 11:31:41 +0000 |
| Subject: | Re: Fallo is_int() | ||
| References: | 1 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-60354@lists.php.net to get a copy of this message | ||
Hola Fco. Javier,
Revisa el manual de PHP (RTFM) y encontrarás la respuesta...
is_int
http://es2.php.net/manual/en/function.is-int.php
bool is_int ( mixed var )
Finds whether the given variable is an integer.
Note: To test if a variable is a number or a numeric string (such as form input, which is always a
string), you must use is_numeric().
Veamos ahora qué se entiende por integer:
http://es2.php.net/manual/en/language.types.integer.php
Integers
An integer is a number of the set Z = {..., -2, -1, 0, 1, 2, ...}.
Syntax
Integers can be specified in decimal (10-based), hexadecimal (16-based) or octal (8-based) notation,
optionally preceded by a sign (- or +).
The size of an integer is platform-dependent, although a maximum value of about two billion is the
usual value (that's 32 bits signed).
PHP does not support unsigned integers.
Integer overflow
If you specify a number beyond the bounds of the integer type, it will be interpreted as a float
instead. Also, if you perform an operation that results in a number beyond the bounds of the integer
type, a float will be returned instead.
-----
En resumen: usa is_numeric para el validador de formulario.
FJSOE> Buenos días, esta mañana estaba preparando un validador de formulario y
FJSOE> quería que un campo viniesen sólo números, para ello empleo is_int(),
FJSOE> pero me he dado cuenta de que esta función falla se le pasas más de 10
FJSOE> dígitos, ¿a alguien la ha pasado?sé que puedo emplear is_numeric y que
FJSOE> funciona sin problemas, pero me ha extrañado que diese este fallo. Tengo
FJSOE> instalado PHP5, por si es cosa de versiones. Os dejo un mini ejemplo
FJSOE> aquí abajo, un saludo;
FJSOE> Javi
FJSOE> Este ejemplo:
FJSOE> <?
FJSOE> $num = 12345678901;
FJSOE> echo (is_int($num))? 'Es un numero<br />':'No es un numero<br
FJSOE> />';
FJSOE> echo (is_numeric($num))? 'Es un numero<br />':'No es un numero<br
FJSOE> />';
?>>
FJSOE> A mi me produce esta salida:
FJSOE> No es un numero
FJSOE> Es un numero
Saludos,
Killer
--
killer@colacao.es