473,224 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

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 88117
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sebek | last post by:
Hello, I'm transforming a XML document in XHTML but I have problems using sub-strings, it will be clearer with an exemple: What I have: <form...
5
by: nboutelier | last post by:
Scenario: you enter "foo bar" into a text field... Is it possible through javascript to select/highlight just "foo"? formObject.select() selects all. I need to select only part of the string....
4
by: Dim | last post by:
I found that C# has some buggy ways to process string across methods. I have a class with on global string var and a method where i add / remove from this string Consider it a buffer... with some...
16
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array...
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
7
by: Sling | last post by:
I code in Rexx on the mainframe which has 2 built-in functions: word(s,i) & words(s). word(s,i) returns the ith word in the s(tring), and words(s) returns the number of words within the s(tring)....
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
4
by: Jean-François Michaud | last post by:
Hello, I've been looking at this for a bit now and I don't see what's wrong with the code. Can anybody see a problem with this? Here is an XSLT snippet I use. <xsl:template match="graphic">...
3
by: Hvid Hat | last post by:
Hi I want to highlight (make it bold) a word in some text I'm getting in XML format. My plan was to replace the word with a bold (or span) tag with the word within the tag. I've found the code...
8
by: SMJT | last post by:
Does anyone know why the string contains function always returns true if the token is an empty string? I expected it to return false. "AnyOldText".Contains("") or...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.