文件下载中断 txt 文件的格式

File download breaks formatting of txt file

我在下载文本文件时遇到问题,它实际上破坏了文件的格式。 我必须制作文本文件的脚本使用 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。

嗯。我相信您的文件没有损坏,但它是您正在使用的编辑器。也许你正在使用记事本。尝试用 Notepad++ 打开。查看显示我如何查看下载文件的图像