3

I have used

get_type($var) 

But it always returns as string.. from the text box

echo "<input type='text' name='value'>"; 
plain jane
  • 1,009
  • 1
  • 8
  • 19
Karthick oc
  • 88
  • 1
  • 2
  • 7

5 Answers5

5

As per the documentation, it's gettype($var) not get_type($var). Check the documentation for more.

웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
5

You will always get strings from HTTP requests - as technically their params are passed as strings.

If you want to check whether a param (or any given value, in fact) is a numeric string, use is_numeric function:

var_dump(gettype('111'));          // 'string'
var_dump(is_int('111'));           // false - as it's a string, not an integer
var_dump(is_numeric('111'));       // true  - this string represents a number
var_dump(is_numeric('something')); // false - and this string doesn't
raina77ow
  • 103,633
  • 15
  • 192
  • 229
3

The function gettype() should only be used to output the datatype of a variable. Testing for special datatypes – with this function – is not recommended, because the returns may change at some point. Instead, the functions is_boolean($var), is_string($var), is_float($var), is_array($var), is_object($var), is_resource($var) and is_null($var) should be used.

For more details : https://stackhowto.com/how-do-you-determine-the-data-type-of-a-variable-in-php/

thomas
  • 785
  • 8
  • 7
0

take a look at all the ctype functions in php you will find the functions you need to determine the type of a string.

DevZer0
  • 13,433
  • 7
  • 27
  • 51
0

You can use gettype(); to check datatype of variable in php. However, the value of the input element of HTML is always wrapped into the string.

To convert string into number or other datatypes, there are a few ways to do so: you can see the solution for it here... https://stackoverflow.com/a/8529678/10743165