使用nl2br混淆Php函数结果
I'm simply experimenting with PHP to prepare me for some upcoming projects and I've encountered a string which won't have <br />
inserted into it even though it is a multi-line string.
The code is simple PHP (which I've enclosed in simple html tags)
$ping = passthru('ping www.google.com');
$ping = htmlspecialchars_decode($ping);
$ping = strip_tags($ping);
$ping = nl2br($ping);
echo $ping;
The result is a multi-line string but without any <br />
tags added, however, the page source shows the result as a mutli-line string so there's definitely multiple lines there but nl2br()
is not doing anything.
Page source (which has mysteriously added extra whitespace lines when I pasted it in here)
<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>
And the actual string shown on the webpage:
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
After extensive Googling all I can find is people who are not using nl2br()
when they should be
What am I missing here?
我只是在尝试使用PHP来为一些即将开展的项目做好准备,而且我遇到了一个赢了的字符串' 即使它是一个多行字符串,也会将 代码很简单PHP(我附上了 在简单的html标签中) p>
结果是一个多行字符串但没有任何字符串 添加了 页面源(当我在这里粘贴时神秘地添加了额外的空白行) p>
网页上显示的实际字符串: p>
经过广泛的Google搜索后,我可以找到所有内容 是那些没有使用 我在这里缺少什么? p>
div>&lt; br /&gt; code>插入其中。 p>
$ ping = passthru('ping www.google.com');
$ ping = htmlspecialchars_decode($ ping);
$ ping = strip_tags($ ping);
$ ping = nl2br($ ping);
echo $ ping;
code> pre>
&lt; br /&gt; code>标签,但是,页面源将结果显示为多行字符串,因此肯定有多行,但
nl2br() code>没有做 任何事情。 p>
&lt; html&gt;
&lt; head&gt;
&lt; title&gt; Derp&lt; / title&gt;
&lt; / head&gt;
&lt; body&gt;&lt; ; p>
使用32个字节的数据访问www.l.google.com [209.85.227.147]:
从209.85.227.147开始:字节= 32次= 44ms TTL = 48
\ nReply自209.85.227.147:字节= 32时间= 28ms TTL = 48
从209.85.227.147开始:字节= 32时间= 40ms TTL = 48
从209.85.227.147开始:字节= 32时间= 29ms TTL = 48
的统计数据为209.85.227.147:
nn数据包:已发送= 4,已接收= 4,已丢失= 0(0%丢失),
近似的往返时间(以毫秒为单位):
最小值= 28毫秒,最大值= 44毫秒,平均值= 35毫秒
&lt; / p&gt;
&lt; / body&gt;
&lt; / html&gt;
code> pre>
使用32个字节的数据Ping www.l.google.com [209.85.227.147]:回复 来自209.85.227.147:bytes = 32 time = 30ms TTL = 48来自209.85.227.147的回复:bytes = 32 time = 29ms TTL = 48来自209.85.227.147的回复:bytes = 32 time = 28ms TTL = 48来自209.85.227.147的回复: bytes = 32 time = 31ms TTL = 48 209.85.227.147的Ping统计信息:数据包:已发送= 4,已接收= 4,已丢失= 0 (0%损失),以毫秒为单位的近似往返时间:最小值= 28毫秒,最大值= 31毫秒,平均值= 29毫秒
code> pre>
nl2br() code>的人 p>
<?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 />
You're misunderstanding what passthru($cmd)
does. It executes $cmd
, but sends stdout
directly to the browser - you do not get the results back as a string. Instead, it returns the return code of the called $cmd
.
If you want to capture output, use exec
, and pass an $output
array by reference.