views:

294

answers:

3

Hi everyone,

Is_numeric() as well as is_int() returns false if the value is 0. What can i do instead to verify that a specific value is numbers only in PHP?

Are we heading straight for the Regular Expressions camp, or are there some nice, handy feature for this out there already?

Thanks!

A: 

It is returning true for me in both cases:

var_dump(is_numeric(0));
var_dump(is_int(0));

Result:

bool(true)
bool(true)
Sarfraz
Very strange. Have no idea of why my test (windows) environment does return false.
Industrial
A: 
var_dump(is_int("0"));

Will pass false because you are passing it the zero as a string literal. You could try passing the same thing as a variable which has gone through (I believe) parseInt("");

Though my php may be a little off, having been Javascripting nonstop the last week or two.

Douglas
Hi! The string isn't being passed as a string.
Industrial
@Industrial that's a paradox ;)
Gordon
@Gordon Duuh. That was one for the wall of fame definitely. The value that is passed were not a string, but only a number. I'll hope that made it understandable ;)
Industrial
A: 

Restarted PHP on the server and it works out well now. Have no idea of why it occored though. Thanks everybody for their help!

Industrial