php 如何在浏览器中回显换行符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10635539/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How To echo a line break in the browser?
提问by Androelpha
I dont know how to echo a new line in PHP. I have tried echo "\n"but it does not work.
我不知道如何在 PHP 中回显新行。我试过了,echo "\n"但它不起作用。
I want to echo new lines in the following code.
我想在以下代码中回显新行。
Code:
代码:
if (file_exists($fName)) {
echo "CreationTime: ".$CreationTime.
"CurrentTime: ".$CurrentTime.
"after ".($fLifeTime)." Days from Creation: ".$fAge;
}
回答by Tufan Bar?? Y?ld?r?m
IF you are looking this output from a browser, you must use <br />tag or, put <pre>before your echo.
如果您正在从浏览器查看此输出,则必须使用<br />标记或放在<pre>您的回声之前。
For new line
example.
对于新行
示例。
if (file_exists($fName)) {
echo "CreationTime: ".$CreationTime. "<br />".
"CurrentTime: ".$CurrentTime. "<br />" .
"after ".($fLifeTime)." Days from Creation: ".$fAge;
}
pre example
前例
if (file_exists($fName)) {
echo "<pre>";
echo "CreationTime: ".$CreationTime. PHP_EOL .
"CurrentTime: ".$CurrentTime. PHP_EOL .
"after ".($fLifeTime)." Days from Creation: ".$fAge;
}
回答by Rukmi Patel
you can do it like this
你可以这样做
if (file_exists($fName)) {
echo "CreationTime: ".$CreationTime.
"<br />CurrentTime: ".$CurrentTime.
"<br />after ".($fLifeTime)." Days from Creation: ".$fAge;
}
回答by Javascript Coder
Try to do like this:--
尝试这样做:--
if (file_exists($fName)) {
echo "CreationTime: ".$CreationTime.
"CurrentTime: ".$CurrentTime.
"after ".($fLifeTime)." Days from Creation: ".$fAge;
echo "<br/>"; //break to new line.
}

