I am trying to replace a tag from a xml. I have stored a xml results through curl in variable. and trying to make a file.xml.
when it
<Topics>
<Topic code="Balances" count="26" pagesize="100" />
</Topics>
with this function , it doesnt return any matches. why?
function get_tag( $tag, $xml ) {
$tag = preg_quote($tag);
preg_match_all('{<'.$tag.'[^>]*>(.*?)</'.$tag.'>}',
$xml,
$matches,
PREG_PATTERN_ORDER);
return $matches[1];
}
Your example is a very poor and slow implementation of parsing a document. Suggestively you should have a look at the
DOMDocumentobject and try to implement it.Basic usage according to your example:
Edit; Sorry – better example now.