|
Posted by Kim Andrι Akerψ on 04/06/06 14:09
Regan wrote:
> Hello,
>
> I was wondering if there is a way to format the output from the
> passthru() command. What I have right now is the following:
>
> $content = passthru("ping -c 4 192.168.0.2", $err);
>
> When I echo $content I get the following:
>
> PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data. 64 bytes from
> 192.168.0.2: icmp_seq=1 ttl=128 time=0.292 ms 64 bytes from
> 192.168.0.2: icmp_seq=2 ttl=128 time=0.284 ms 64 bytes from
> 192.168.0.2: icmp_seq=3 ttl=128 time=0.281 ms 64 bytes from
> 192.168.0.2: icmp_seq=4 ttl=128 time=0.276 ms --- 192.168.0.2 ping
> statistics --- 4 packets transmitted, 4 received, 0% packet loss, time
> 3005ms rtt min/avg/max/mdev = 0.276/0.283/0.292/0.013 ms
>
> But when I look at the source of the page I have the following:
>
> PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data.
> 64 bytes from 192.168.0.2: icmp_seq=1 ttl=128 time=0.292 ms
> 64 bytes from 192.168.0.2: icmp_seq=2 ttl=128 time=0.284 ms
> 64 bytes from 192.168.0.2: icmp_seq=3 ttl=128 time=0.281 ms
> 64 bytes from 192.168.0.2: icmp_seq=4 ttl=128 time=0.276 ms
>
> --- 192.168.0.2 ping statistics ---
> 4 packets transmitted, 4 received, 0% packet loss, time 3005ms
> rtt min/avg/max/mdev = 0.276/0.283/0.292/0.013 ms
>
> I have tried using nl2br and that did not do a thing. How am I to
> output the results from the ping command and have them display on the
> webpage as they do in the source for the webpage? Thanks for your
> help!
nl2br() works on a string you pass to it, and passthru() outputs
directly to the browser without the ability to perform tasks on the
returned output. You could enclose the output like this:
<pre><?php passthru("ping -c 4 192.168.0.2"); ?></pre>
Or, you could use exec() instead:
<?php
$contents = exec("ping -c 4 192.168.0.2");
echo nl2br($contents);
?>
--
Kim AndrΓ© AkerΓΈ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Navigation:
[Reply to this message]
|