HTML中定义的textbox如下: ↓
<input name="my_test" value="1" type="text" maxlength="3" readonly="readonly" size="15" style="margin-left: 15px;" />表单按钮提交的时候 后台接受如下: ↓
$num0 = (string)$_POST["my_test"];
$num1 = (int)$_POST["my_test"];
$num2 = intval($_POST["my_test"]);
$num3 = $num0*1;
echo $num0;
echo $num1;
echo $num2;
echo $num3;运行后打印如下:
1 0 0 0这是怎么回事 为什么强制类型装换1的时候 给我全都默认转为0了??????求解答
<input name="my_test" value="1" type="text" maxlength="3" readonly="readonly" size="15" style="margin-left: 15px;" />表单按钮提交的时候 后台接受如下: ↓
$num0 = (string)$_POST["my_test"];
$num1 = (int)$_POST["my_test"];
$num2 = intval($_POST["my_test"]);
$num3 = $num0*1;
echo $num0;
echo $num1;
echo $num2;
echo $num3;运行后打印如下:
1 0 0 0这是怎么回事 为什么强制类型装换1的时候 给我全都默认转为0了??????求解答
<form method="post" action="test.php" id="bunruicodeform">
<input type="text" value="1" name="my_test1" />
<input type="text" value="5" name="my_test2"/>
</form>
后台:if(!get_magic_quotes_gpc()){
addslashes($_POST);
addslashes($_GET);
}
if($_GET["type"]){
$num1 = (int)$_GET["my_test1"];
$num2 = (int)$_GET["my_test2"];
echo $num1."-".num2 ;
}结果:
0_5很奇怪 很纠结 怎么搞?
$num2 = (int)$_GET["my_test2"];
这个地方写错了应该是
$num1 = (int)$_POST["my_test1"];
$num2 = (int)$_POST["my_test2"];
if($_GET["type"]){
$num1 = (int)$_POST["my_test1"];
$num2 = (int)$_POST["my_test2"];
echo $num1."-".$num2 ;
}
?>
<form method="post" action="test.php?type=2" id="bunruicodeform">
<input type="text" value="1" name="my_test1" />
<input type="text" value="5" name="my_test2"/>
<input type="submit" value="submit">
</form>这段代码没有任何问题,如果这段代码在你那输出的还是 不正确的,你的php版本是?
我都是在utf-8下测试 没有说的事.并且都是英文 更没有机会在这上面出错了.
addslashes($_POST);
addslashes($_GET);
}
if($_GET["type"]){
$num1 = (int)$_GET["my_test1"];
$num2 = (int)$_GET["my_test2"];
echo $num1."-".num2 ;
}你要用它们不必addslashes,直接转int就可以了,入库才需要addslashes,安全性不是字符串的安全性,是数据库的安全性。另外,先trim再intval试试。
编码那里传的数组 X;
对数字进行了字符连接,结果肯定是字符。你可以在代码里写上:
$n1=3;
$n2=5;
echo $n1.'_'.$n2;
看看,结果肯定是3_5;
对于你的类型转换问题,个人猜测是HTTP的问题,以前看到过书上提到过。建议你对每个转换后的类型var_dump一下。