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

  • Home
  • SEARCH
  • 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 8229513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:49:19+00:00 2026-06-07T16:49:19+00:00

I am trying to pull data from a source, then parse the data for

  • 0

I am trying to pull data from a source, then parse the data for 3 different fields: “title”, “link”, “description” and then output the data. However, the loop appears to load the first 10 articles, but then turns into a never ending loop . How do I fix this?

<?php

#Load in File
$xmlUrl ="http://sports.yahoo.com/mlb/rss.xml";
$ConvertToXml = simplexml_load_file($xmlUrl);

# -> Setup XML
$newsStory = $ConvertToXml->channel->item;

# -----> Load News Stories
for($i = 0;i<10; $i++){

    $title=$newsStory[$i]->title;
    //$link=$newsStory[$i]->link;
    $desc=$newsStory[$i]->description;

    echo '<hr>';
    echo 'Title:'.$title.'<br />';
    //echo 'Link:'.$link.'<br />';
    echo 'Description'.$desc.'<br>';
    echo '<hr>';

}

?>

The XML I’m parsing:
img

  • 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-07T16:49:21+00:00Added an answer on June 7, 2026 at 4:49 pm

    You have created an endless for-loop:

    for($i = 0;i<10; $i++){
    

    It is endless because the middle expression is always truthy:

    i < 10
    

    It gives: “Notice: Use of undefined constant i – assumed ‘i'” so it is:

    'i' < 10
    

    And "i" is always smaller than 10 because it evaluates to 0 in that operator context.

    Enable error reporting to the highest level on your development platform so that you spot these minor error quickly.

    Simple solution is to add the missing $:

    for ($i = 0; $i < 10; $i++) {
                 ^
    

    But actually in the context of your overall script you might want to prefer a conditional exit:

    # -> Setup XML
    $newsStories = $ConvertToXml->channel->item;
    
    # -----> Load News Stories
    foreach ($newsStories as $index => $newsStory) {
    
        if ($index === 10) break;
    
        $title = $newsStory->title;
        //$link = $newsStory->link;
        $description = $newsStory->description;
    
        echo '<hr>';
        echo 'Title:' . $title . '<br />';
        //echo 'Link:' . $link . '<br />';
        echo 'Description' . $description . '<br>';
        echo '<hr>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SimpleXML to parse a data file from an external source. I'm trying
I am trying to pull data from SQL, and then write it to a
I'm trying to pull JSON data from another source by using the jquery.get method.
I'm currently trying to pull data from a database using a variable and then
I'm trying to pull data from the YouTube API into a local MySQL table.
I'm trying to pull in data from a remote SQL Server. I can access
I am trying to pull out data from the table I had from the
I'm trying to pull some data from a webpage. I have it partially working,
I am trying to pull data from my populated javascript table. How do I
I am trying to pull data from a table I have imported into 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.