【发布时间】:2018-08-16 22:08:52
【问题描述】:
我在下载文本文件时遇到问题,它实际上破坏了文件的格式。 我必须制作文本文件的脚本使用 str_pad 来确定要解析到文本文件中的项目之间所需的空格数。
http://www.lokalradio.no/rapport/gramo/upload/gramorapport-Radio%20Metro%20Mj%C3%B8sbyene-opprettet%2016.08.2018.txt 它似乎在浏览器中正确显示,但是当使用“页面另存为”下载文件然后在文本编辑器中重新打开时,格式被破坏。
我可以在 php 脚本中做些什么或做些什么来防止这种情况发生吗?使用此脚本制作文本文件
$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, "\n");
fclose($fh);
写入文件时,字符集设置为 ISO-8859-1 以完全支持北欧字符。从浏览器下载可能会破坏格式,因为它假定为 UTF-8。
【问题讨论】:
标签: php text-files monospace