【发布时间】:2015-03-17 13:58:14
【问题描述】:
如果我想从我的网站动态下载一个包含数据库信息的文本文件,我会使用类似的东西:
$name = $_GET["download"];
$file = get_file_data($name);
if ($file) {
header("Content-Disposition: attachment; filename=".$file["custom_name"].".txt");
header("Content-Type: text/plain");
echo $file["stuff"];
exit();
}
其中$file["stuff"] 是直接从数据库读取的纯文本字符串。
但是,存储的文本中似乎没有任何明确的换行符,相反,当它们裸露时,它们看起来像是段落块之间的大空间。
(当然,当在 HTML 页面上的 pre 标记中显示时,会出现换行符,因为在大多数现代浏览器中都有 pre 的 CSS。)
例如
The Last Question by Isaac Asimov © 1956 The last question was asked for the first time, half in jest, on May 21, 2061, at a time when humanity first stepped into the light. The question came about as a result of a five dollar bet over highballs, and it happened this way:
我怎样才能像这样遍历任何字符串并在每行的末尾强制执行PHP_EOL?
【问题讨论】:
-
什么是大空间?多个空格、制表符等?
-