duanjie1339 2013-10-24 13:41
浏览 24

为什么file_put_contents写的文本文件会写双行?

Good morning, friends. I've struggled and googled and I can't seem to find an answer. If it's been answered on here already and I missed it, please feel free to direct me to what I missed.

I have the following bit of PHP code. It works fine when I run it on my Mac (and the non-Windows machines of some friends), but when I run it on Windows (where it's going to live here at work), it writes each line to the text file twice. PHP here at work is 5.3.6 running on IIS 6.

Any help is greatly appreciated.

<?php

$fltSupervision = trim(htmlentities($_POST["txtSupervision"]));
$fltDrugTestUA = trim(htmlentities($_POST["txtDrugTestUA"]));
$fltAlcoholSensor = trim(htmlentities($_POST["txtAlcoholSensor"]));
$fltTotal = trim(htmlentities($_POST["txtTotal"]));
$fltSurcharge = trim(htmlentities($_POST["txtSurcharge"]));

$strTransaction = $fltSupervision . "\t" . $fltDrugTestUA . "\t" . $fltAlcoholSensor . "\t" . $fltSurcharge . "\t" . $fltTotal . PHP_EOL;
echo $strTransaction;

$file = 'fees.txt';
file_put_contents($file, $strTransaction, FILE_APPEND);

?>

Jeremy

  • 写回答

5条回答 默认 最新

  • doudeng2016 2013-10-24 13:48
    关注

    It probably has something to do with a missing favicon.ico.

    Try changing .htaccess to this:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ index.php [NC,L]
    

    And try creating a favicon.ico file by creating an empty .txt file renaming it to favicon.ico.

    Many browsers look for a favicon.ico file and if that file doesn't exist and your .htaccess file is setup to direct to your script, the script will be executed twice and the text will be added twice to fees.txt.

    评论

报告相同问题?

悬赏问题

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