This is my code.
$fr = fopen("php://stdin", "r");
$input = fgets($fr);
if (preg_match('/^-?[0-9]{1,4}$/', $input)) {
echo "Integer.";
} else if (preg_match('/^[-+]?[0-9]*\.?[0-9]+$/', $input)) {
echo "Float.";
} else if (preg_match('/[a-zA-Z\s]^[0-9]/', $input)) {
echo "string.";
}
I will get the $input
variable from the command line entered. I need to find what datatype the variable is either int, float, string.
Tried gettype() method but it is always string. So only tried with preg_match
.
Although in this also i am not getting the correct output.
Ex: 1.2e3 i am getting as string