我有这个表格:<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 = 价值电子邮件 = 价值通行证 = 价值我不需要打印$_POST['i']值。任何想法?
1 回答
米脂
TA贡献1836条经验 获得超3个赞
添加一个 IF 来测试$variable循环i迭代,然后使用continue;
您还可以使用一个写入每一行的所有数据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 关注
- 83 浏览
添加回答
举报
0/150
提交
取消