如何在 PHP 中创建新行
本文将介绍在 PHP 中利用转义序列创建新行的不同方法,如\n
和\r\n
。
在 PHP 中使用\n
转义序列来创建新行
在 PHP 中,我们有不同的方法来创建新行,其中最简单的方法是使用\n
转义序列。请注意,当你在程序中包含这个转义序列时,需要使用双引号。执行命令的正确语法如下。
echo("\n");
下面的程序显示了我们如何在 PHP 中使用\n
转义序列来创建一个新行。
<?php
echo("There is a new line after this. \n");
echo("This program shows a new line. \n");
?>
输出:
There is a new line after this.
This program shows a new line.
我们可以使用两次\n
函数在两行文本之间创建一个行距。
<?php
echo("There is a new line after this. \n\n");
echo("This program shows a new line. \n");
?>
输出:
There is a new line after this.
This program shows a new line.
在 PHP 中使用\r\n
转义序列创建新行
在 PHP 中,我们也可以使用\r\n
转义序列来创建新的行;此外,它还返回回车,重新设置指针并从左边开始。正确使用它的语法如下。
echo("\r\n");
下面是应用此方法的程序:
<?php
echo("There is a new line after this. \r\n");
echo("This program shows a new line. \n");
?>
输出:
There is a new line after this.
This program shows a new line.
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布,任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站。本站所有源码与软件均为原作者提供,仅供学习和研究使用。如您对本站的相关版权有任何异议,或者认为侵犯了您的合法权益,请及时通知我们处理。