Php 自动生成文件的第一行为空
我正在通过PHP生成一个临时文件,并使用以下代码强制下载:Php 自动生成文件的第一行为空,php,file,Php,File,我正在通过PHP生成一个临时文件,并使用以下代码强制下载: $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).'"' );
$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;
这里的问题是第一行是空行,输出从第二行开始。
这是此脚本的输出:
1 .
2 . this is a sample text to be displayed in the file
我需要做的是避免生成第一行。更好的方法是使用这样的数组
$foo = array();
while($a = mysql...)
{
$foo[] = $a['key'];
}
//your headers
echo implode(PHP_EOL,$foo);
当我在关闭PHP的
?>
后,或者通过简单地删除?>
在您的问题中使用了几乎伪代码,删除了使用enter键创建的新行时,这一行就消失了。我们怎样才能找到你们多余的线路?代码也没有多大意义。使用此代码,您的文件只存储一行。您的php文件中可能有一行空行。确保标记位于第一行和最后一行。这里的问题不在查询本身。我甚至试过用echo“hello world”和问题percists生成文件。你到底是如何保存此文件并确认其内容的?