This is a discussion on string contains a substring within the PHP Language forums, part of the PHP Programming Forums category; How does one tell if a string contains a certain substring? For example: $a = popen("/bin/ping -c1 $rhost&...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
How does one tell if a string contains a certain substring?
For example: $a = popen("/bin/ping -c1 $rhost", "r"); $read = fread($a, 1024); pclose($a); if($read contains "1 received") { print "Ping Succeded"; } else { print "Ping Failed"; } |
|
|||
|
hokieghal99 wrote:
> How does one tell if a string contains a certain substring? > > For example: > > $a = popen("/bin/ping -c1 $rhost", "r"); > $read = fread($a, 1024); > pclose($a); if (strpos($read, '1 received') !== false) { // do not use != instead!! echo 'Ping Succeded'; } else { echo 'Ping Failed'; } http://www.php.net/strpos and, since you're already reading the manual, check all other string functions :) http://www.php.net/manual/en/function.strpos.php -- --= my mail box only accepts =-- --= Content-Type: text/plain =-- --= Size below 10001 bytes =-- |
|
|||
|
"hokieghal99" <hokiegal99@hotmail.com> wrote in message
news:btf4ad$400$1@solaris.cc.vt.edu... > How does one tell if a string contains a certain substring? > > For example: > > $a = popen("/bin/ping -c1 $rhost", "r"); > $read = fread($a, 1024); > pclose($a); > if($read contains "1 received") > { > print "Ping Succeded"; > } > else > { > print "Ping Failed"; > } > > > Pssst. Ping doesnt work on on machines, sometimes php wont let you execute a system command, try this: http://www.gzentools.com/snippetview...=fuzzyping.php -- Mike Bradley http://www.gzentools.com -- free online php tools |
|
|||
|
Pedro Graca wrote:
> hokieghal99 wrote: > >>How does one tell if a string contains a certain substring? >> >>For example: >> >> $a = popen("/bin/ping -c1 $rhost", "r"); >> $read = fread($a, 1024); >> pclose($a); > > > if (strpos($read, '1 received') !== false) { > // do not use != instead!! > echo 'Ping Succeded'; > } else { > echo 'Ping Failed'; > } > > http://www.php.net/strpos > > > and, since you're already reading the manual, check all other string > functions :) > > http://www.php.net/manual/en/function.strpos.php That works great. Thanks for the string info... I'll read up on it! |
|
|||
|
CountScubula wrote:
> Pssst. Ping doesnt work on on machines, sometimes php wont let you execute > a system command, > try this: > http://www.gzentools.com/snippetview...=fuzzyping.php > > -- > Mike Bradley > http://www.gzentools.com -- free online php tools Umm... it works on mine... no problem at all. Why do you say this??? |
|
|||
|
"hokieghal99" <hokiegal99@hotmail.com> wrote in message
news:btf7hs$9a7$2@solaris.cc.vt.edu... > CountScubula wrote: > > Pssst. Ping doesnt work on on machines, sometimes php wont let you execute > > a system command, > > try this: > > http://www.gzentools.com/snippetview...=fuzzyping.php > > > > -- > > Mike Bradley > > http://www.gzentools.com -- free online php tools > > Umm... it works on mine... no problem at all. Why do you say this??? > I meant some machines, not all. There was another post a couple of days ago, somone wanted to have the ping to user time in his script, but was unable to run system commands (php was locked down) I originaly posted a ping code snippet, but it didnt work for him, so I wrote that workaround. -- Mike Bradley http://www.gzentools.com -- free online php tools |