Re: Searchingfor text within a string

From: Date: Mon, 28 Aug 2000 02:09:01 +0000
Subject: Re: Searchingfor text within a string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-13881@lists.php.net to get a copy of this message
On 25 Aug, 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 > What about exploding the results using the comma as a separator. Then you could grab the third(?) element of the array, trim leading and trailing white space and read off the first chars up to the % sign. Cheers -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#13881) next »