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. 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, "

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.

图片转代码服务由CSDN问答提供 功能建议

我在下载文本文件时遇到问题,它实际上破坏了文件的格式。 脚本我必须使文本文件使用str_pad来使正在解析到文本文件中的项之间所需的空格数。 gramo / upload / gramorapport-Radio%20Metro%20Mj%C3%B8sbyene-opprettet%2016.08.2018.txt 它似乎在浏览器中正确显示,但是当使用“保存页面为”下载文件然后重新打开时 在文本编辑器中,格式化被破坏了。

我可以在php脚本中做些什么或者根本不能防止这种情况发生吗? 文本文件是使用此脚本生成的

  $ fh = fopen($ myFile,'w')或die(“无法打开文件”); 
(nfwrite)($  fh,str_pad($ res ['dato'],19)); 
 nfwrite($ fh,str_pad($ res ['spilletid'],6)); 
fwrite($ fh,str_pad($ res ['songid'  ],77)); 
fwrite($ fh,str_pad($ res [“tittel”],50)); 
 nfwrite($ fh,str_pad($ res [“artist”],50)); 
fwrite($  fh,“
 nclclose($ fh); 

写入文件时,charset设置为ISO-8859-1以满 支持北欧人物。 从浏览器下载可能会破坏格式,因为它假定为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

    打赏 评论

相关推荐 更多相似问题