我有這個表格:<form method='post'> <input name='i' type='hidden' value='' > <input name='email' type='text' > <input name='pass' type='password' > <input type="submit" ></form>以及打印 .txt 文件中的數(shù)據(jù)的 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;?>結(jié)果是:i = 價值電子郵件 = 價值通行證 = 價值我不需要打印$_POST['i']值。任何想法?
1 回答

米脂
TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超3個贊
添加一個 IF 來測試$variable循環(huán)i迭代,然后使用continue;
您還可以使用一個寫入每一行的所有數(shù)據(jù)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 關(guān)注
- 132 瀏覽
添加回答
舉報
0/150
提交
取消