2

我不知道如何在 PHP 中回显一个新行。我已经尝试过echo "\n",但它不起作用。

我想在下面的代码中回显新行。

代码

if (file_exists($fName)) {
   echo "CreationTime: ".$CreationTime.
        "CurrentTime: ".$CurrentTime.
        "after ".($fLifeTime)." Days from Creation: ".$fAge;
   }
4

4 回答 4

8

如果您正在从浏览器查看此输出,则必须使用<br />标记或放在<pre>回显之前。

对于新行
示例。

if (file_exists($fName)) {
   echo "CreationTime: ".$CreationTime. "<br />".
        "CurrentTime: ".$CurrentTime. "<br />" .
        "after ".($fLifeTime)." Days from Creation: ".$fAge;
   }

前例

 if (file_exists($fName)) {
      echo "<pre>";
       echo "CreationTime: ".$CreationTime. PHP_EOL .
            "CurrentTime: ".$CurrentTime. PHP_EOL .
            "after ".($fLifeTime)." Days from Creation: ".$fAge;
       }
于 2012-05-17T12:14:55.947 回答
1

你可以这样做

if (file_exists($fName)) {
    echo "CreationTime: ".$CreationTime.
    "<br />CurrentTime: ".$CurrentTime.
    "<br />after ".($fLifeTime)." Days from Creation: ".$fAge;
}
于 2012-05-17T12:14:46.810 回答
0

尝试这样做:-

if (file_exists($fName)) {
   echo "CreationTime: ".$CreationTime.
        "CurrentTime: ".$CurrentTime.
        "after ".($fLifeTime)." Days from Creation: ".$fAge;
echo "<br/>"; //break to new line.
   }
于 2012-05-17T12:15:35.413 回答
0

也许尝试使用PHP_EOLnl2br()

if (!file_exists($fName)) {
    $info = "CreationTime: " . $CreationTime . PHP_EOL .
        "CurrentTime: ". $CurrentTime . PHP_EOL .
        "after ". ($fLifeTime)." Days from Creation: " . $fAge;

    echo nl2br($info);
}
于 2012-05-17T12:45:51.133 回答