0

I have an image generated with PHP that contains dynamically generated text. The data it was originally sourcing from has changed to a different format, from JSON to XML. I'm unfamiliar with XML and related PHP commands.

What I wish to do is to echo a specific part of the XML page/file. For example, if the data is structured in this manner:

<sometag>
    <anothertag>
        <tag1>ABC123</tag1>
        <tag2>DEF456</tag2>
        <tag3>GHI789</tag3>
    </anothertag>
</sometag>

If I want to echo the contents of, say, tag2, what would I need to do? Is there some sort of $xml->tag2 feature, similar to how it works with JSON?

Phil
  • 157,677
  • 23
  • 242
  • 245
Hiigaran
  • 829
  • 10
  • 28

1 Answers1

2

You could use SimpleXML library.

$xml = new SimpleXMLElement($xml_string);
echo $xml->anothertag->tag2;
//DEF456
Phil
  • 157,677
  • 23
  • 242
  • 245
catzilla
  • 1,901
  • 18
  • 31