Amit Dhamu

Software Engineer

SimpleXML

Learn how to use SimpleXML to parse XML documents using PHP.

<?xml version="1.0" encoding="UTF-8"?>
<songs>
    <song>
        <artist><![CDATA[Coldplay]]></artist>
        <title><![CDATA[Paradise]]></title>
        <album><![CDATA[Mylo Xyloto]]></album>
    </song>
</songs>
$xml_file = file_get_contents('songs.xml');
$xml = new SimpleXMLElement($xml_file);
$songs = $xml->song;

foreach ($songs as $song) {
    echo $song->artist // returns Coldplay
    echo $song->title // returns Paradise
    echo $song->album // returns Mylo Xyloto
}

 simplexml / xml / php / rss

Encode & Decode JSONError Document

Show Comments

Made with by Amit Dhamu.
© MMXX. All rights reserved.