Jump to content

Print RSS feed to table


drizac

Recommended Posts

Hello

 

I thought I had it all figured out, but apparently not.

 

I want to write content from an RSS feed into an HTML table. I dont want all of it in one big pile, so I tried using some tricks and regular expressions.

 

This is a snippet from the feed:

 

 <?xml version="1.0" encoding="utf-8" ?> 
- <root>
- <products>
- <product>
  <categoryPath>Stuff</categoryPath> 
  <productName>product_name_01</productName> 
  <productCode>22-356-12/756</productCode> 
  <eanNumber /> 
  <manufactorSku /> 
  <price>9999.00</price> 
  <deliveryCost>0.00</deliveryCost> 
  <deliveryTime>5 - 10 days</deliveryTime> 
  <availability>In Stock</availability> 
  <url>http://home.com/boats/fuel.aspx</url> 
  </product>
  ...
  </products>
- </root>

 

This is my code:

$html = file_get_contents('http://home.com/feed/feedfile.aspx');

preg_match_all('/<product>.+<\/product>/', $html , $strng); // Reg_ex

echo "<table border=\"1\"> <tr><th>Link</th></tr>";
foreach($strng as $url) {
echo "<tr><td>";
echo $url;
print_r($url);
echo "</td></tr>";

}

 

I am getting this result:

 

Link Title

ArrayArray ( )

 

Can anyone help me identify what am I doing wrong and help me in the right direction.

Link to comment
https://forums.phpfreaks.com/topic/244993-print-rss-feed-to-table/
Share on other sites

try something like this:

 

$html = file_get_contents('http://home.com/feed/feedfile.aspx');
preg_match_all("/\<product\>(.*?)\<\/product\>/si", $html , $strng); // Reg_ex
echo "<table border=\"1\"> <tr><th>Link</th></tr>";
foreach($strng[0] as $url) {
echo "<tr><td>";
echo $url;
echo "</td></tr>";
}

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.