Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2005, 10:00 AM
Authorized User
 
Join Date: Jun 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default RSS Feed to PHP in Array?

Hi,
I have an array form of data from an RSS feed (XML file) and I am trying to print out the news topics but having a problem displaying it,

My code so far:
require("inc.rss2array.php");
           $rss_array = rss2array("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/technology/rss.xml");

print "<pre>";
           print_r($rss_array);
           print "</pre>";

I used the above to print out what ws in the array and get:

Array
(
    [inside_image] =>
    [items] => Array
        (
            [0] => Array
                (
                    [title] => Tiny drives set for space boost
                    [link] => http://news.bbc.co.uk/go/rss/-/2/hi/...gy/4411649.stm
                    [description] => Hitachi demonstrates a leap in hard drive technology which will lead to one-inch hard drives that can hold 60GB.
                )

            [1] => Array
                (
                    [title] => Google to start 'video blogging'
                    [link] => http://news.bbc.co.uk/go/rss/-/2/hi/...gy/4412125.stm
                    [description] => Search engine firm Google is to begin an experiment in "video blogging", according to co-founder Larry Page.
                )

            [2] => Array

---------cut for reasons of space and patience!!!-------------
        )

    [channel] => Array
        (
            [title] => BBC News | Technology | World Edition
        )

)





 .....but keep getting errors on the foreach loop around the array, like this:

foreach ($rss_array as $item){
 echo "item: $item<br>";

 foreach ($item as $subitem){
 echo "subitem: $subitem<br>";

foreach ($subitem as $subsubitem){
 echo "subsubitem: $subsubitem<br>";
 }
 }
 }

like:
Warning: Invalid argument supplied for foreach() on line 23 -----line 23 is: foreach ($item as $subitem)

at the start of the loop and

Warning: Invalid argument supplied for foreach() on line 26 -----line 26 is: foreach ($subitem as $subsubitem)

at the end of the loop, I also only want to print out say the first 10 records too?

Hope you can help

Many Thanks

Sami
 
Old April 17th, 2005, 04:53 PM
Authorized User
 
Join Date: Apr 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The very first for each makes $item = zero becouse it ig getting the value of $rss_array['inside_image']. When the data you need starts at $rss_array['item'].

  This should point you in the right direction. Let me know if you don't know how to take it from there.

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent





Similar Threads
Thread Thread Starter Forum Replies Last Post
validate rss feed arafat.eajaz RSS and Atom 2 September 6th, 2012 08:56 AM
2 Questions on XSLT for RSS Feed Tachyon XSLT 4 June 14th, 2007 06:00 PM
Rss Feed in php surendran RSS and Atom 2 October 22nd, 2005 12:59 AM
RSS Feed Shibu Classic ASP XML 0 January 21st, 2005 08:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.