为了账号安全,请及时绑定邮箱和手机立即绑定

Foreach 2 变量 $_POST

Foreach 2 变量 $_POST

PHP
largeQ 2022-12-23 13:10:17
我有这个表格:<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);


查看完整回答
反对 回复 2022-12-23
  • 1 回答
  • 0 关注
  • 47 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信