php - 将 Php 函数结果与 nl2br 混淆

标签 php command-line nl2br

我只是尝试使用 PHP 来为即将进行的一些项目做好准备,但我遇到了一个没有 <br /> 的字符串。即使它是多行字符串,也可以插入其中。

代码是简单的 PHP(我将其包含在简单的 html 标签中)

$ping = passthru('ping www.google.com');
$ping = htmlspecialchars_decode($ping);
$ping = strip_tags($ping);
$ping = nl2br($ping);
echo $ping;

结果是一个多行字符串,但没有任何<br />添加标签,但是,页面源将结果显示为多行字符串,因此肯定有多行,但是 nl2br()没有做任何事情。

页面源代码(当我将其粘贴到此处时,它神秘地添加了额外的空白行)

<html>

    <head>

        <title>Derp</title>



    </head>

    <body><p>



Pinging www.l.google.com [209.85.227.147] with 32 bytes of data:

Reply from 209.85.227.147: bytes=32 time=44ms TTL=48

Reply from 209.85.227.147: bytes=32 time=28ms TTL=48

Reply from 209.85.227.147: bytes=32 time=40ms TTL=48

Reply from 209.85.227.147: bytes=32 time=29ms TTL=48



Ping statistics for 209.85.227.147:

    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

    Minimum = 28ms, Maximum = 44ms, Average = 35ms

</p>

    </body>

</html>

网页上显示的实际字符串:

Pinging www.l.google.com [209.85.227.147] with 32 bytes of data: Reply from 209.85.227.147: bytes=32 time=30ms TTL=48 Reply from 209.85.227.147: bytes=32 time=29ms TTL=48 Reply from 209.85.227.147: bytes=32 time=28ms TTL=48 Reply from 209.85.227.147: bytes=32 time=31ms TTL=48 Ping statistics for 209.85.227.147: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 28ms, Maximum = 31ms, Average = 29ms

经过广泛的谷歌搜索后,我只能找到不使用 nl2br() 的人。当他们应该的时候

我在这里缺少什么?

最佳答案

<?php 
$ping = `ping www.google.com`;
$ping = nl2br($ping);
echo $ping;
?>

<br />
Pinging www.l.google.com [209.85.147.104] with 32 bytes of data:<br />
<br />
Reply from 209.85.147.104: bytes=32 time=24ms TTL=53<br />
Reply from 209.85.147.104: bytes=32 time=23ms TTL=53<br />
Reply from 209.85.147.104: bytes=32 time=23ms TTL=53<br />
Reply from 209.85.147.104: bytes=32 time=25ms TTL=53<br />
<br />
Ping statistics for 209.85.147.104:<br />
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),<br />

Approximate round trip times in milli-seconds:<br />
    Minimum = 23ms, Maximum = 25ms, Average = 23ms<br />

关于php - 将 Php 函数结果与 nl2br 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6903696/

相关文章:

JavaScript 代码不适用于多个 HTML 元素

php - 使用PHP向mysql插入多维数组

shell - 使用 shell 脚本合并 2 个文件的列

go - 在 GoLang 中定义独立的标志集

php - 没有获得与 php 中 mysql 数据库中存储的格式相同的格式

php - 创建一个变量,该变量是两个其他变量的总和

php - 哪一个是用于信用卡/借记卡付款的正确 PayPal API 代码?

mysql - 我安装了 MySQL,但无法通过终端访问它

php - strip <br>(n12br) 从数据库字段获取

php - Nl2br 对除 <li> 标签之外的数据