string contains a substring

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&...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-06-2004
hokieghal99
 
Posts: n/a
Default string contains a substring

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";
}



Reply With Quote
  #2 (permalink)  
Old 01-06-2004
Pedro Graca
 
Posts: n/a
Default Re: string contains a substring

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 =--
Reply With Quote
  #3 (permalink)  
Old 01-06-2004
CountScubula
 
Posts: n/a
Default Re: string contains a substring

"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


Reply With Quote
  #4 (permalink)  
Old 01-06-2004
hokieghal99
 
Posts: n/a
Default Re: string contains a substring

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!

Reply With Quote
  #5 (permalink)  
Old 01-06-2004
hokieghal99
 
Posts: n/a
Default Re: string contains a substring

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???

Reply With Quote
  #6 (permalink)  
Old 01-06-2004
CountScubula
 
Posts: n/a
Default Re: string contains a substring

"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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:33 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0