Reply to Re: Formatting Output From passthru() Command

Your name:

Reply:


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)

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация