By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,760 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,760 IT Pros & Developers. It's quick & easy.

StrPos Help

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.