dongyi2425 2018-08-16 22:08
浏览 64
已采纳

文件下载会破坏文本文件的格式

I am having issues with a text file when it is downloaded that it actually breaks the formatting of the file. The script I have to make the text file uses str_pad to make the number of spaces needed between the items that are being parsed into the text file.

http://www.lokalradio.no/rapport/gramo/upload/gramorapport-Radio%20Metro%20Mj%C3%B8sbyene-opprettet%2016.08.2018.txt It appears to show correctly in the browser, but when the file is downloaded using Save Page As and then reopened in a text editor, the formatting is broken.

Is there something I can do in the php script or anything at all to prevent this from happening? The text file is made using this script

$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, str_pad($res['dato'], 19));
fwrite($fh, str_pad($res['spilletid'], 6));
fwrite($fh, str_pad($res['songid'], 77));
fwrite($fh, str_pad($res["tittel"],50));
fwrite($fh, str_pad($res["artist"],50));
fwrite($fh, "
");
fclose($fh);

When the file is written the charset is set to ISO-8859-1 to have full support for Nordic characters. The download from browser might break the formatting because it assumes UTF-8.

  • 写回答

1条回答 默认 最新

  • dongtanghuan1885 2018-08-17 00:06
    关注

    Well. I believe your file is not broken but it is the editor which you are using. Maybe you are using notepad. Try opening with Notepad++. See the image which shows how I see the downloaded file

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题