Foreach 2 var $_POST

我有这个表格:


<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']值。


任何想法?


MMMHUHU
浏览 37回答 1
1回答

米脂

添加一个 IF 来测试$variable循环i迭代,然后使用continue;您还可以使用一个写入每一行的所有数据fwrite<?php$handle = fopen("data.txt", "a");foreach($_POST as $variable => $value) {&nbsp; &nbsp; if ( $variable == 'i' ){&nbsp; &nbsp; &nbsp; &nbsp; continue;&nbsp; &nbsp; &nbsp; &nbsp;// will stop this itereation and continue with the next&nbsp; &nbsp; }&nbsp; &nbsp; // make one write for all 4 bits of data.&nbsp; &nbsp; fwrite($handle, "$variable = $value \r\n");}fwrite($handle, "\r\n");fclose($handle);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5