Reserved word in XML parsing?

I have the following:

<?php

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

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

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

    // Source of Article Info-->
    $SrcTitle=$newsStory[$i]->title;
    $SrcLink=$newsStory[$i]->link;

    // Actual News Article Info -->
    $title=$newsStory[$i]->item->title;
    $desc=$newsStory[$i]->item->description;


    echo '<hr>';
    echo '<strong>'.'Title:'.$title.'</strong>'.'(via: <a href=\''.$SrcLink.'\'>'.$SrcTitle.'</a>'.'<br />';
    //echo 'Link:'.$link.'<br />';
    echo 'Description'.$desc.'<br>';
    echo '<hr>';
}

It outputs just 1 result when it should output about 10 results...

This line: $SrcLink=$newsStory[$i]->link; the "link" word appears to possibly be a 'reserved' word here since its purple on my editor as shown in the image below:

What am I doing wrong here?

Answers


Not sure why your IDE is highlighting that purple, but here is the problem:

$newsStory = $ConvertToXml->channel;

needs to be changed to:

$newsStory = $ConvertToXml->channel->item;

Each entry in the RSS feed is in an <item> tag so you need to be looping over those for the actual feed entries.


Colour-coding often suffers from this problem. Since the word is being used as a property name (as shown by the ->), it can be literally anything - there are no reserved words in this case.

I would suggest var_dump(count($newsStory)) so you can see exactly how many elements there are to loop through. If it's 1, then you probably have an issue with your $newsStory variable - you can var_dump that too.


Need Your Help

For any finite floating point value, is it guaranteed that x - x == 0?

language-agnostic floating-point precision ieee-754 signedness

Floating point values are inexact, which is why we should rarely use strict numerical equality in comparisons. For example, in Java this prints false (as seen on ideone.com):

Generating the RGBF color

colors hex rgb

I need to generate the RGB(Filter) which is RGBF shortcut color, which numbers are totally different as of the simple RGB color, just take a look at this aliceblue color example: