tags:

views:

32

answers:

2

Hi there , i have a string with xml data in it. how do i parse it in php? thank you

+1  A: 

SimpleXML

BoltClock
+2  A: 

Try with simple XML, here's an example:

do.php:

<?php
$xml_str = file_get_contents('xmlfile.xml');
$xml = new SimpleXMLElement($xml_str);
$items = $xml->xpath('*/item');

foreach($items as $item) {
    echo $item['title'], ': ', $item['description'], "\n";
}

xmlfile.xml:

<?xml version="1.0" encoding="UTF-8"?>
<xml>
    <items>
        <item title="Hello World" description="Hellowing the world.." />
        <item title="Hello People" description="greeting people.." />
    </items>
</xml>
aularon