自动生成的文件的第一行是空白的 [英] First line of an auto genrated file is blank
本文介绍了自动生成的文件的第一行是空白的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过PHP生成一个临时文件,并强制它使用下面的代码下载:
$ liste =this是要在文件
$ filename =temp_code.txt中显示的示例文本;
header(Content-Type:application / octet-stream);
header('Content-Disposition:attachment; filename =''。basename($ filename)。'');
echo $ liste;
这里的问题是第一行是空行,输出从第二行开始。
这是脚本的输出:
1。
2。这是一个示例文本显示在文件中
我需要做的是避免产生这个第一行。
解决方案更好的方法是使用这样的数组。
$ foo = array();
while($ a = mysql ...)
{
$ foo [] = $ a ['key'];
//你的头文件
echo implode(PHP_EOL,$ foo);
I am generating a temporary file via PHP and forcing it to be downloaded using this code:
$liste = "this is a sample text to be displayed in the file"
$filename = "temp_code.txt";
header ("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="'.basename($filename).'"' );
echo $liste;
The problem here is that the first line is a blank line and the output starts in the second line. this is the output of this script:
1 .
2 . this is a sample text to be displayed in the file
What I need to do is to avoid generating this first line.
解决方案
A better way to do this is by using an array like this.
$foo = array();
while($a = mysql...)
{
$foo[] = $a['key'];
}
//your headers
echo implode(PHP_EOL,$foo);
这篇关于自动生成的文件的第一行是空白的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文