这是我的代码。
$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.";
}
我将从$input
输入的命令行获取变量。我需要找到变量是 int、float、string 的数据类型。
尝试了gettype()方法,但它始终是字符串。所以只尝试了preg_match
.
虽然在这我也没有得到正确的输出。
例如:1.2e3 我得到了字符串