469,326 Members | 1,411 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

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

Jul 17 '05 #1
5 87901
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 =--
Jul 17 '05 #2
"hokieghal99" <ho********@hotmail.com> wrote in message
news:bt**********@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
Jul 17 '05 #3
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!

Jul 17 '05 #4
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???

Jul 17 '05 #5
"hokieghal99" <ho********@hotmail.com> wrote in message
news:bt**********@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
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Sling | last post: by
4 posts views Thread by Jean-François Michaud | last post: by
3 posts views Thread by Hvid Hat | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.