Re: Searchingfor text within a string
| From: | Patrick Brown | Date: | Wed, 30 Aug 2000 03:43:32 +0000 |
| Subject: | Re: Searchingfor text within a string | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14304@lists.php.net to get a copy of this message | ||
Are you sure? Line 2 (echo $string;) in my code does return the following
text:
PING 127.0.0.1 (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1:
icmp_seq=0 ttl=255 time=0.3 ms --- 127.0.0.1 ping statistics --- 1 packets
transmitted, 1 packets received, 0% packet loss round-trip min/avg/max =
0.3/0.3/0.3 ms 0
(Note: all on one line)
I had a suggestion to use explode to break the ping result into three pieces
separated at the comma and looking at the first characted in part three. I
need to learn a little more about arrays to take this on.
--Pat
"Robin Vickery" <robin@planet-three.co.uk> wrote in message
news:kspumsnjnf.fsf@Robin.planet...
> pbrown@sla.com ("Patrick Brown") writes:
>
> > I just tried that with no success. I always get "Green Light". Here's
the
> > code I used:
> >
> > <?
> > passthru('ping -c 1 1.1.1.1', $string);
> > echo $string;
> > echo "<br>\n";
> > if(strstr($string,"100%")){
> > echo "Red Light<br>\n";
> > } else {
> > echo "Green Light<br>\n";
> > }
> > ?>
>
> OK, passthru doesn't put the output of ping in $string, it puts the
> return value of ping in it, ie. false if there were no errors
> and true if something went wrong.
>
> If you want the actual output of ping, try using backticks like so:
>
> $string =
ping -c 1 127.0.0.1;
>
> -robin
>
> --
> Robin Vickery...............................................
> Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK
> Email: robin@planet-three.net Phone: +44 (0)870 729 5444
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>