RE: [PHP] Searchingfor text within a string

From: Date: Mon, 28 Aug 2000 03:10:57 +0000
Subject: RE: [PHP] Searchingfor text within a string
Groups: php.general 
Request: Send a blank email to php-general+get-13882@lists.php.net to get a copy of this message
> > 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) > > > > I'll do something like: > > > > if ($loss = '100%'){ > > display a red light; > > } > > else { > > display a green light; > > } > 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. More to the point, where else would "100%" occur in the string? if (strstr($pingresults, "100%")) { // Display a red light } else { // Display a green light } ? Jason

« previous php.general (#13882) next »