Re: Searchingfor text within a string

From: Date: Sat, 26 Aug 2000 06:12:20 +0000
Subject: Re: Searchingfor text within a string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-13777@lists.php.net to get a copy of this message
probably something like this: $string = " PING 1.1.1.1 (1.1.1.1): 56 data bytes --- 1.1.1.1 ping statistics --- 1 packets transmitted, 0 packets received, 100% packet loss"; ereg("([0-9]{1,3})%",$string,$p); $percent = $p[1]; There are also some PHP4 Perl like regex functions (preg, etc), but I haven't used them yet. Hans On Fri, 25 Aug 2000, Patrick Brown wrote: > I'm trying to search for a piece of text within a long string. It is for a > basic ping utility that will just provide a green or red light. > > An example string is: > > PING 1.1.1.1 (1.1.1.1): 56 data bytes --- 1.1.1.1 ping statistics --- 1 > packets transmitted, 0 packets received, 100% packet loss > (all on one line) > > This is the result of the following command: > > passthru('ping -c 1 2.1.1.1', $ping); > echo $ping; > > I need to look for the '100%' part of the string and assign it as a > variable. > > I'll do something like: > > if ($loss = '100%'){ > display a red light; > } > else { > display a green light; > } > > > Thanks, > > Pat > > > > > -- > 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 > > > Hans Anderson ~ me@hansanderson.com PO Box 426, Missoula, MT 59806 | PHP, Search Engines, SQL (800)397-9116 / (406)549-6524 | Databases, Flash Multimedia, http://www.hansanderson.com | Killer Audio Production, http://www.goofiness.com | Minty Fresh Breath.

« previous php.general (#13777) next »