473,396 Members | 2,055 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,396 software developers and data experts.

StrPos Help

I'm trying to use strpos to find these xml tags so I can pull out the
text data; but the bracket chars won't let the function work. Is there
another way to do this?

$php_XML_tag = "<codeFacility>ZNY</codeFacility>";
$pos = strpos($php_XML_tag, '<codeFacility>');
print $pos;

results is $pos == 0

Oct 10 '05 #1
2 1837

ra*********@primemail.com wrote:
I'm trying to use strpos to find these xml tags so I can pull out the
text data; but the bracket chars won't let the function work. Is there
another way to do this?

$php_XML_tag = "<codeFacility>ZNY</codeFacility>";
$pos = strpos($php_XML_tag, '<codeFacility>');
print $pos;

results is $pos == 0


Of course it's zero! ;) You're asking it to find the character offset
of "<codeFacility>" within $php_XML_tag, and it's telling you that it's
0, i.e. right at the beginning of the string.

Try looking at regular expressions in the PHP manual, or possibly even
the dedicated XML functions.

--
Oli

Oct 10 '05 #2
ra*********@primemail.com wrote:
I'm trying to use strpos to find these xml tags so I can pull out the
text data; but the bracket chars won't let the function work. Is there
another way to do this?

$php_XML_tag = "<codeFacility>ZNY</codeFacility>";
$pos = strpos($php_XML_tag, '<codeFacility>');
print $pos;

results is $pos == 0


That's the correct result... if the function was failing, you'd get a
boolean FALSE instead...

$pos = strpos($php_XML_tag, '<codeFacility>');
if($pos===FALSE){
// the function call failed (not found)
}else{
echo "Pattern starts at character offset $pos of the string."
}

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Oct 10 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: yawnmoth | last post by:
say i have the following php script: <? if (!is_int(strpos("a","aaa"))) // if (strpos("a","aaa") === false) print "no match"; else print "match"; ?> when i run it, i am told there is no...
21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
3
by: julian_m | last post by:
file AddHTML.htm: ---------------------------- This line is <b>ok</b><br> This line is <b>ok</b><br> This line is <b>ok</b><br> <?PHP echo "This one has code prohibited "; ?> This line is...
2
by: drec | last post by:
I am trying to right an if statment using strpos to determine if the string exists in the variable, however I seem to be getting the wrong effect. Here is my script. <?php $dn = "ABC-DEF"; ...
1
by: Dana Cartwright | last post by:
At php.net, the following paragraph is the first thing in the definition of strpos: "Returns the numeric position of the first occurrence of needle in the haystack string. Unlike the strrpos()...
18
by: jodleren | last post by:
Hi! I was reading php.net for a way to find a number of characters in a strings. Say I want to look for a b and c ind $string. As far as I could see, there is no function for that. So, I can...
2
by: daschicken | last post by:
Hi, ive written the following php code. its a part of an admin form to add a text. when adding the text %bild the script is supposed to swap that with the link to the picture already stored in the...
3
by: Tarik Monem | last post by:
Hi, here I am again :-) I'm trying to compare the contents of two arrays and if there's a match, then I would like to place the contents of that one index of the array into a "new" third array. ...
1
by: Michael Sharman | last post by:
Not quite sure what's happening here, the docs for strpos() say: "Returns the position as an integer. If needle is not found, strpos() will return boolean FALSE." Looks fine, I can simply...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.