Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if php variable is a number or not [duplicate]

Tags:

php

Possible Duplicate:
What's the correct way to test if a variable is a number in PHP?

I have two variables coming in from a form:

$minNo = mysql_real_escape_string($_GET["minNo"]);
$maxNo = mysql_real_escape_string($_GET["maxNo"]);

How can I check whether they are numerical values or not?

like image 375
CJS Avatar asked Mar 18 '12 20:03

CJS


People also ask

How do you check if a number is double in PHP?

php $var_name=127.55; if (is_double($var_name)) echo 'This is a double value. <br>'; else echo 'This is not a double value.

How do you check if a variable is number or not in PHP?

The is_numeric() function checks whether a variable is a number or a numeric string. This function returns true (1) if the variable is a number or a numeric string, otherwise it returns false/nothing.

How do I check if a string contains only digits in PHP?

PHP – How to check if String contains Number(s)? ctype_digit() function returns true if the string passed to it has digits for all of its characters, else it returns false.

Is Double A data type in PHP?

PHP supports the following data types: String. Integer. Float (floating point numbers - also called double)


2 Answers

Try is_numeric.

Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal notation (0xFF) is allowed too but only without sign, decimal and exponential part.

like image 198
j08691 Avatar answered Sep 20 '22 13:09

j08691


Use is_numeric function, it returns bool value:

is_numeric($element)
like image 30
MarcinJuraszek Avatar answered Sep 21 '22 13:09

MarcinJuraszek