Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8105273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:07:09+00:00 2026-06-06T00:07:09+00:00

I have a php file setup to pull through ONE XML data feed, What

  • 0

I have a php file setup to pull through ONE XML data feed, What I would like to do is load up to 4 feeds into it and if possible make it select a random item too. Then parse that into an jQuery News Ticker.

My current PHP is as follows…

<?php
$feed = new DOMDocument();
$feed->load('/feed');
$json = array();

$json['title'] = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('title')->item(0)->firstChild->nodeValue;
$json['description'] = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('description')->item(0)->firstChild->nodeValue;
$json['link'] = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('link')->item(0)->firstChild->nodeValue;

$items = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('item');

$json['item'] = array();
$i = 0;


foreach($items as $item) {

   $title = $item->getElementsByTagName('title')->item(0)->firstChild->nodeValue;
   $description = $item->getElementsByTagName('description')->item(0)->firstChild->nodeValue;
   $pubDate = $item->getElementsByTagName('pubDate')->item(0)->firstChild->nodeValue;
   $guid = $item->getElementsByTagName('guid')->item(0)->firstChild->nodeValue;

   $json['item'][$i++]['title'] = $title;
   $json['item'][$i++]['description'] = $description;
   $json['item'][$i++]['pubdate'] = $pubDate;
   $json['item'][$i++]['guid'] = $guid; 

   echo '<li class="news-item"><a href="#">'.$title.'</a></li>';

}


//echo json_encode($json);


?>

How can I modify this to load more than one feed into the file?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:07:11+00:00Added an answer on June 6, 2026 at 12:07 am

    The simplest approach to doing this is wrapping another loop around the code you have. It’s not the cleanest way but will probably suffice for the purpose.

    In general, IMO, it’s always beneficial to learn the basics of the language first. E.g. PHP manual on foreach

    This is roughly what the loop needs to look like:

    $my_feeds = array("http://.....", "http://.....", "http://.....");
    
    foreach ($my_feeds as $my_feed)
     {
      // This is where your code starts
      $feed = new DOMDocument();
      $feed->load($my_feed); <--------------- notice the variable
      $json = array();
    
     ... and the rest of the code
    
     }
    

    this will walk through all the URLs in $my_feeds, open the RSS source, fetch all the items from it, and output them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The setup: I have a standard .php file (index.php) that contains two includes, one
I have some setup code in my functions.php file that sets permalinks and adds
Some setup background first: I have a cronjob which runs a PHP file called
I have the following code setup for my admin_add in my photocategories_controller.php file. This
I have a PHP File with something like this: <script type=text/javascript> var page =
I have a PHP file with shell commands running through a screen, the commands
I have the following build.xml file setup in phpUnderControl. <target name=phpunit> <exec executable=phpunit dir=${basedir}/httpdocs
I have successfully setup an HTML form in PHP File #1, and it is
I would like to access a PHP file whose name has UTF-8 characters in
I have settings.php file that I want to keep some constants in, like my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.