我只是尝试使用 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/