Jump to content

Recommended Posts

I have a bunch of rss feeds written in php that I host on my home server that display as sports ticker information on my mobile phone. Basically, scripts parse the url string for each sport in espn's bottom line app. I'm stuck on one sport in particular, though... Golf.

Here's the url that I am trying to parse into RSS feed for golf scores:

http://sports.espn.go.com/sports/golf/bottomLineGolfLeaderboard

 

Basically, all I want to do is have each players score as the title of an RSS news item. I'm using it with an ajax feed scroller on my mobile phone so it essentially operates as a sports score ticker.
 

As such, when the ajax feed scroller reads my golf script, it should scroll each of the following in order (based on the url above):

RBC Canadian Open Leaderboard
Final Round Complete
1. Brandt Snedeker (-16) F
2. William McGirt (-13) F ........

 

Regarding what I've been working with, I tried working on a few more things, and it looks like I am getting a little closer. The code now at least appears to be counting/seeing each score item, but unfortunately it's not populating the score itself as an rss item.

 

Here's the code I'm working with:

<?

// begin rss feed

header("Content-Type: text/xml");

echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n";

echo "<rss version=\"2.0\">\n\n";

echo "<channel>\n";

$results = array();
// Get page
$page = file_get_contents("http://sports.espn.go.com/sports/golf/bottomLineGolfLeaderboard");
    
// grab all variables out of the page
preg_match_all("/&([^=]+)=([^&]+)/", $page, $matches);



//loop through all the variables on the page
    
foreach ($matches[1] as $match) {
      
// get score      

preg_match("/s_right\d+_\d+/", $match, $temp);  
          
$results = $temp['2'];

          

echo "<item>";

echo "<title>". $results ."</title>";

echo "</item>";

}

echo "</channel>";

echo "</rss>"


?>

Which gives me this output:

<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel> <item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item><item><title></title>
</item><item><title></title></item>
</channel></rss>

I just don't get where I am going wrong. Am I missing something that is causing the output data for the array not to be produced as titles? I've tried tinkering with everything I can think of based on my limited knowledge. Can anyone provide some insight?

Link to comment
https://forums.phpfreaks.com/topic/280640-parsing-url-string-to-rss-feed/
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.