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