PHP实现换行的方法有5种:换行符、HTML换行标签、CSS换行样式、PHP_EOL常量、nl2br()函数。

如何使用PHP实现换行
在PHP中实现换行有以下方法:
1. 换行符
使用换行符直接插入换行:
立即学习“PHP免费学习笔记(深入)”;
<code class="php">echo "This is the first line \nThis is the second line";</code>
2. HTML换行标签
使用<br>标签实现换行:
<code class="php">echo "This is the first line<br>This is the second line";</code>
3. CSS换行样式
使用CSS样式"white-space: pre"实现换行,使文本保持原始格式:
<code class="php">echo "<p style='white-space: pre;'>This is the first line\nThis is the second line</p>";</code>
4. PHP_EOL常量
使用PHP_EOL常量表示不同的平台下的换行符:
<code class="php">echo "This is the first line" . PHP_EOL . "This is the second line";</code>
5. nl2br()函数
nl2br()函数将换行符转换为<br>标签:
<code class="php">echo nl2br("This is the first line\nThis is the second line");</code>











