3

I have used

get_type($var) 

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

echo "<input type='text' name='value'>"; 
2
  • are you getting the values via Get/Post? Commented Aug 16, 2013 at 6:35
  • gettype() you mean? Commented Aug 16, 2013 at 6:36

5 Answers 5

5

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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/

Comments

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.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.