Return to Snippet

Revision: 62458
at February 24, 2013 20:18 by apphp-snippets

Initial Code
// this is a sample xml string
$xml_string="<?xml version='1.0'?>
    <article id='Article1'>
        <title>Title 1</title>
        <content>..text here..</content>
    <article id='Article2'>
        <title>Title 2</title>
        <content>..text here..</content>
// load this xml string using simplexml function
$xml = simplexml_load_string($xml_string);
// loop through the each node
foreach($xml->article as $key){
   // attribute are accessted by
   echo $key['id'].' ';
   // node are accessted by -> operator
   echo $key->title.' ';
   echo $key->content.'<br />';

Initial URL

Initial Description
This code shows how to parse XML file in easy way using PHP.

Initial Title
Parsing XML File with PHP

Initial Tags
php, xml

Initial Language