dongyi2425 2018-08-16 14: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-16 16: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

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部