3
,比如我有下面的代码
<form action="viewer.php" method="post">
<input type="number" name="roll" min="0" max="9999999" size="7" maxlength="7" required>
</form>
和viewer.php文件
<?php
$c=$_POST["roll"]; echo gettype($c);
?>
而且无论总是返回字符串我是否提交花车,整数或strngs -__-
和我该怎么做得到我的预期答案?
在此先感谢
因为当从POST有效载荷('foo = 123&bar = -1'或multipart/fields)中读取时,它们*是*所有字符串。使用['is_numeric()'](http://php.net/is_numeric)或'ctype_ *'函数来探测类型相同的内容。 – mario 2015-04-04 07:45:35
使用以下代码检查 $ c =(is_numeric($ _ POST ['roll'])?(int)$ _ POST ['roll']:0); – 2015-04-04 07:48:29
gettype()返回PHP变量var的类型。对于类型检查,使用is_ *函数。你可以从http://www.hacksparrow.com/check-object-type-in-php.html获得参考 – 2015-04-04 07:48:51