php - Need ctype_digit to return true for negative numbers also -


i need take string , return true if positive or negative numbers in string. there way this?

$rating = "-25"; if (!ctype_digit($rating)) { echo "not digit."; }  else { echo "is digit."; }  

result:

not digit.

need result:

is digit.

ctype_digit() works on values consists only of digits. $rating = -25; false being treated ascii code in particular case (explained below), , "-25" invalid because - not digit. type juggle think you're looking is_numeric()

echo is_numeric( "-25"); or echo ctype_digit((integer) $var);

however latter return true if string cannot cast integer. have value of 0 if that's case.

important: if pass literal integer in range of -128 , 255 ctype_digit() value converted character defined in ascii table. if not number, false expected. other integer value normal expected behavior.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -