亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Foreach 2 var $_POST

Foreach 2 var $_POST

MMMHUHU 2023-12-25 16:18:38
我有這個表格:<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);


查看完整回答
反對 回復 2023-12-25
  • 1 回答
  • 0 關注
  • 137 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號