Jump to content

How to parse XML product feed using PHP??


rahulephp

Recommended Posts

I am a php programmer but I am not so good with XML files.

For a price comparison website, I need to parse the Amazons XML feed to store product data into the database.

 

Can anyone please help me to find out such a simple script to parse Amazon XML product feed???

(Actually, I need each product data in array to be stored into the database)

 

Thank you in advance.

 

Link to comment
https://forums.phpfreaks.com/topic/211053-how-to-parse-xml-product-feed-using-php/
Share on other sites

You can use it like this:

 

<?php
//
$rss=simplexml_load_file("http://www.somesite.com/rss/yourtarget.xml");// can also be yourtarget.rss
//
foreach($rss->channel->item as $post){
  //create multi-dimentional array to hold element values
  $myarray[0] = array( "Url" => $post->link,
                       "Title" => $post->title,
                       "Description" => $post->description,
  );
}
?>

 

Call it as follows:

 

echo $myarray[0]['Url'];

 

or put into an element like this:

 

<td><?php echo $myarray[0]['Url']; ?></td>

 

Hope this helps

I just noticed I forgot to add a counter:

 

use like this:

 

<?php
//
$rss=simplexml_load_file("http://www.somesite.com/rss/yourtarget.xml");// can also be yourtarget.rss
//
$i=0;
foreach($rss->channel->item as $post){
  //create multi-dimentional array to hold element values
  $myarray[$i] = array( "Url" => $post->link,
                       "Title" => $post->title,
                       "Description" => $post->description,
  );
  $i++;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.