我有这个表格:<form method='post'> <input name='i' type='hidden' value='' > <input name='email' type='text' > <input name='pass' type='password' > <input type="submit" ></form>以及在 .txt 文件中打印数据的 PHP 代码:<?php $handle = fopen("data.txt", "a"); foreach($_POST as $variable => $value) { fwrite($handle, $variable); fwrite($handle, "="); fwrite($handle, $value); fwrite($handle, "\r\n"); } fwrite($handle, "\r\n"); fclose($handle); exit;?>结果是:i = 值email = 值pass = 值我不需要打印$_POST['i']值。任何的想法?
1 回答
qq_笑_17
TA贡献1818条经验 获得超7个赞
添加一个 IF 测试然后忽略循环的迭代$variable使用icontinue;
您还可以使用一个为每一行写入所有数据fwrite
<?php
$handle = fopen("data.txt", "a");
foreach($_POST as $variable => $value) {
if ( $variable == 'i' ){
continue; // will stop this itereation and continue with the next
}
// make one write for all 4 bits of data.
fwrite($handle, "$variable = $value \r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
- 1 回答
- 0 关注
- 60 浏览
添加回答
举报
0/150
提交
取消