dtwxt88240 2013-02-27 19:47
浏览 20
已采纳

$ _POST使用相同的密钥?

I have a POST form, than when submitted uses both key and value to replace lines in a set of .ini files.

$reading = fopen('Original/file.ini', 'r');
$writing = fopen('file.ini', 'w');

while (!feof($reading)) {
    $line = fgets($reading);
    foreach ( $_POST as $key => $value )
    {
        if (stristr($line, $key.)) {
            $line = "   ".$key." = ".$value.";
";
        }
    }
    fputs($writing, $line);
}
fclose($reading); fclose($writing);

Now this is working fine. However, now I need to edit several files, of which many contains the same key. Of course, the file name and path the said files are not the same, so I was wondering if there's any way to group the text inputs, so I can keep using my PHP solution?

As an example, say I have both "product1.ini" and "product2.ini", but both have a "productPrice =" line. Any suggestions?

  • 写回答

2条回答 默认 最新

  • dousonghs58612 2013-02-27 19:55
    关注

    I would suggest changing the way you post the variables, so that the settings for each ini file are posted in an array named for that ini file.

    So you'll be wanting to get a post array like this:

    array(
        'product1' => array(
            'key1'=>'value1',
            'key2'=>'value2'
        ),
        'product2' => array(
            'key1'=>'value1',
            'key2'=>'value2'
        ),
    )
    

    This will give the ability to post settings for as many ini files as you like.

    In case you haven't posted nested arrays before, this is easy to achieve. The HTML input field names just need to be formatted with the array keys in square brackets:

    <input name='product1[key1]'>
    

    Hope that helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大