php中的表单输入为整数
我目前有一个包含输入的表单:php中的表单输入为整数,php,integer,Php,Integer,我目前有一个包含输入的表单: <input type="text" name="score" id="score" value="" /> 我对上述问题的看法是,float将通过此测试,而不使用类似(int)$score的东西,我不能使用is\u int()来否定is\u numeric检查 我是不是遗漏了什么 用于确保字符串仅由数字组成,因此是一个整数-从技术上讲,这将返回true以及超出int范围的非常大的数字注意此方法将不识别负数为什么不检查是否为数字,然后转换为int?我不
<input type="text" name="score" id="score" value="" />
我对上述问题的看法是,float将通过此测试,而不使用类似(int)$score
的东西,我不能使用is\u int()
来否定is\u numeric
检查
我是不是遗漏了什么 用于确保字符串仅由数字组成,因此是一个整数-从技术上讲,这将返回
true
以及超出int范围的非常大的数字注意此方法将不识别负数为什么不检查是否为数字
,然后转换为int
?我不想更改他们提供的输入,因此如果他们给我32.5,那么我想在error@timothystringer那你为什么要这么做验证它是否是一个整数,而不是字符串、浮点、十六进制等?请尝试@DarylGill,因为这是一个只获得整数分数的测试结果,所以我需要确保这就是我接受的全部内容。谢谢,这看起来可能是我需要的
<?php
$score = $_POST['score'];
if(ctype_digit($score) && $score <= 40){
// Do good stuff
} else {
// Don't do good stuff
}
?>
<?php
$score = $_POST['score'];
if(ctype_digit($score) && $score <= 40){
// Do good stuff
} else {
// Don't do good stuff
}
?>