【问题标题】:Newlines in PHP not working [duplicate]PHP中的换行符不起作用[重复]
【发布时间】:2013-12-14 04:02:36
【问题描述】:

试图让 php 给我新的线路,即使在环顾四周后它也无法正常工作。我正在使用 \r\n 它不显示但也不给我换行回车。

任何建议将不胜感激!

<?php
if (!$socket = @fsockopen("xxx.xxx.xxx.xxx", 22, $errno, $errstr, 1))
{
   echo "<font color='red'><strong>servername.domain.com(xxx.xxx.xxx.xxx) is Offline!\r\n</strong></font>";
}
else
{
echo "<font color='green'><strong>servername.domain.com(xxx.xxx.xxx.xxx) is Online!\r\n</strong></font>";
fclose($socket);
}
if (!$socket = @fsockopen("xxx.xxx.xxx.xxx", 22, $errno, $errstr, 1))
{
   echo "<font color='red'><strong>servername2.domain.com(xxx.xxx.xxx.xxy) is Offline!\r\n</strong></font>";
}
else
{
    echo "<font color='green'><strong>servername2.domain.com(xxx.xxx.xxx.xxy) is Online!\r\n</strong></font>";
fclose($socket);
}
?>

【问题讨论】:

  • 请改用&lt;br&gt;

标签: php


【解决方案1】:

如果您通过浏览器运行页面,则使用 &lt;br&gt; html 标记,并且您通过命令提示符运行脚本,然后使用 \n

【讨论】:

    【解决方案2】:

    尝试&lt;br&gt; 而不是\n。因为\n 无法被HTML 识别

    【讨论】:

    • 好吧,如果您决定使用&lt;pre&gt; 或其他方式。
    【解决方案3】:

    当您希望写入 HTML 格式时,最好使用
    强制换行。

    【讨论】:

      【解决方案4】:

      试试

      **<br>**
      

      如果 /n 已经来自数据库,请尝试 nl2br

      【讨论】:

        猜你喜欢
        • 2017-09-30
        • 2014-01-21
        • 2018-12-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-27
        • 2010-11-16
        相关资源
        最近更新 更多