Php – Conditional SimpleXML possible

htmlphpsimplexmlxml

I am pulling content from an XML file with SimpleXML.

I was wondering if it is possible to display a certain node depending on the contents of the node, e.g.

<article>
    <title>PHP</title>
    <content>yada yada yada</content>
</article>

<article>
    <title>JAVASCRIPT</title>
    <content>yodo yodo yodo</content>
</article>

Can SimpleXML find a specific title and then display the article for that title?

Display article whose title is 'PHP'.

I really hope this is possible.

Thanks to anyone who replies.

Best Solution

You could use an XPath expression like //article[title='PHP']/content

Related Question