我让PHP从一个很长的字符串中保存一个输出文件。我希望此输出的代码格式正确,因此我想在某些点添加换行符。我一直在尝试使用"\n"
,但是由于某些原因没有解决问题。这是相关的代码:
foreach($headerColumn as $hColumn) {
$outputString .= '<td>' . $hColumn . '</td>' . "\n";
};
在这里,我将"\n"
添加到字符串的末尾,但是由于某种原因,它的输出如下:
<thead>
<tr><td>Name</td><td>Ticker</td><td>Buy Date</td><td>Current Yield</td>
</tr>
</thead>
实际上,什么时候我希望每个人都按自己的立场行事..有什么想法吗?如果它与文件的内容类型有关,这是我的文件写调用:
header('Content-Disposition: attachment; filename="sample.txt"');
header('Content-Type: text/plain'); # Don't use application/force-download - it's not a real MIME type, and the Content-Disposition header is sufficient
header('Content-Length: ' . strlen($outputString));
header('Connection: close');
echo $outputString;
谢谢!
我想您要使用的是PHP_EOL
:
PHP_EOL(字符串)此平台的正确“行尾”符号。自PHP 4.3.10和PHP 5.0.2起可用
因此,以您的示例为例:
$outputString .= '<td>' . $hColumn . '</td>' . PHP_EOL;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句