0

我有一个纯文本文件(text.txt):

11. Bonus: In humans, it is composed of 24 vertebrae plus the sacrum and coccyx. For ten points each:
[10] Identify this support structure found in almost all chordates. An excessive curvature of this structure results in scoliosis, and it usually takes a slim "S" shape in an upright human.
ANSWER: spine (or spinal column; accept backbone; accept vertebral column)
[10] The embryos of many chordates contain this precursor to the spinal column, which is essentially a flexible support rod made of collagen. Unlike most other chordates, lancelets retain this structure as adults.
ANSWER: notochord
[10] These members of the subphylum Urochordata possess notochords as larvae, but then promptly lose it and settle down as sessile filter feeders devoid of any vertebrate characteristics.
ANSWER: tunicates (or sea squirts)

12. Bonus: This novel's protagonist is chased by Detective Fix, who thinks he is a bank robber. For ten points each:
[10] Identify this Jules Verne novel in which Phileas Fogg bets that he can circumnavigate the globe in a certain amount of time.
ANSWER: Around the World in Eighty Days (or Le tour de monde en quatre-vingts jours)
[10] In this Verne novel, Professor Lindenbrock finds a coded note in a Snorri Sturulson book, prompting an adventure through the subterranean world before escaping during an eruption of Stromboli.
ANSWER: Journey to the Center of the Earth (or Voyage au centre de la Terre)
[10] This novel is a sequel to both In Search of the Castaways and Twenty Thousand Leagues Under the Sea. In it, Cyrus Smith and other Union soldiers escape from Richmond on a hot-air balloon, but get stuck in the title locale.
ANSWER: The Mysterious Island (or L'Île mystérieuse)

13. Bonus: He owns the spear Gungnir and sacrificed an eye to drink from the Well of Mimir. For ten points each:
[10] Name this owner of the ravens Hugin and Munin who was the chief Norse deity and father of the Aesir.
ANSWER: Odin (accept Wotan or Woden)
[10] With his brothers Vili and Ve, Odin killed this primordial giant to build the world. He was formed in Ginnungagap by the union of fire and ice.
ANSWER: Ymir (accept Augelmir or close pronunciations of that)
[10] This cold and icy realm met with the fiery Muspelheim to create Ymir. According to some sources, the wicked dead are sent to this place instead of Hel.
ANSWER: Niflheimr

在我的 PHP 脚本中,我试图读取这个文件,以便稍后解析它,但是当我读取文件时,没有出现换行符,整个事情看起来就像一条长线。

这是我的PHP:

ini_set('auto_detect_line_endings',true);
$text = file_get_contents("test.txt");
echo $text;

它有什么不同,我在mac上使用Textedit来创建纯文本文件。

4

3 回答 3

1

我认为这是因为文本文件中的换行符存储为 '\n' ,因此 HTML 无法识别它。为此,您必须全部替换\n为,<br />以便正确回显它们。

例子:

$text=str_replace("\n","<br />",$text);

我希望它有帮助..!!

编辑:

您还可以使用<pre>$text 周围的标签按原样打印它。

例子:

echo "<pre>".$text."</pre>";
于 2013-06-25T21:19:51.830 回答
0

添加header('Content-Type: text/plain');到脚本的顶部。所以它看起来像:

<?php
header('Content-Type: text/plain'); 
ini_set('auto_detect_line_endings',true);
$text = file_get_contents("test.txt");
echo $text;
?>

在 Chrome 中查看源输出:http: //pastie.org/8080064

于 2013-06-25T20:56:44.643 回答
0

这是因为 PHP 输出的 HTTP 内容类型标头默认设置为“text/html”。换行符仍然存在(尝试查看源代码)

于 2013-06-25T20:47:42.893 回答