Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自动生成文件的第一行为空_Php_File - Fatal编程技术网

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).'"' );

我正在通过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).'"' );
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生成文件。你到底是如何保存此文件并确认其内容的?