473,587 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1842

ra*********@pri memail.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*********@pri memail.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.co m
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
1973
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 match, when there actually is.
21
6522
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 Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to...
3
2045
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 <b>ok</b><br> This line is <b>ok</b><br> ----------------------------
2
1779
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"; $pos = strpos( $dn, "ABC-DEF" ); if ( $pos != FALSE ) {
1
1432
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() before PHP 5, this function can take a full string as the needle parameter and the entire string will be used." I find the reference to "strrpos"...
18
5789
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 either? 1) run through the string and test using in_array('a', 'b', 'c') 2) run through array and test using strpos( $items.... Where I find #2 the...
2
1764
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 mysql db. it works perfectly fine until the $id variable reaches "100". I dont understand why it works for every number from 1 till 99 but not...
3
1399
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. Here's the code: $myComboVar = array(); for($someVar=0;$someVar<count($myTempArray);$someVar++) {
1
1256
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 do: if(strpos("michael", "m") But then the docs go on to say:
0
7915
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
8205
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. ...
1
7967
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
6619
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...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.