/ Published in: PHP
This code shows how to parse XML file in easy way using PHP.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // this is a sample xml string $xml_string="<?xml version='1.0'?> <text> <article id='Article1'> <title>Title 1</title> <content>..text here..</content> </article> <article id='Article2'> <title>Title 2</title> <content>..text here..</content> </article> </text>"; // load this xml string using simplexml function // 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 />'; } ?>
URL: http://www.apphp.com/index.php?snippet=php-parsing-xml-file