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
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>";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.