473,545 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 88130
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
"hokieghal9 9" <ho********@hot mail.com> wrote in message
news:bt******** **@solaris.cc.v t.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
"hokieghal9 9" <ho********@hot mail.com> wrote in message
news:bt******** **@solaris.cc.v t.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
4340
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 href="identification.php?PHPSESSID=134134&page=2&param=3" > </form> what I want:
5
3275
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. -Nick
4
2265
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 values and separators class { private string globalvar = ""; private void manipulate (whattodo ) //substring, join, etc....
16
5853
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 with the following elements arr(0) = "MyString" arr(1) = 40 arr(2) = "Hello world"
11
5333
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 (strIn.Substring(410, 10).Trim = "") Then 'Something processed Else 'Something processed
7
43566
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). Is there something equivalent in C#, preferably built-in (assumed better performance), or sample code? Thanks in advance.
94
4647
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 that I found inside of a string. Any ideas?
4
3251
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"> <xsl:param name="path" /> <fo:block padding-after="12pt">
3
3945
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 below and it works fine as long as I'm not adding tags around the to parameter. Can anyone explain to me why it doesn't work with tags? And it needs...
8
4645
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 "AnyOldText".Contains(String.Empty)
0
7475
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7918
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7436
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5981
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1897
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.