Pulling specific data from a remote XML file with PHP

I am able to successfully connect to the 3rd party XML file and not generate any PHP errors, however, the results come back empty. Not sure how to parse the xml data when using simplexml_load_file. URL is open on the server and I can fetch all data, however, when attempting to specify what data is being pulled the results come back blank.

[php]<?php
$xml = simplexml_load_file(‘http://xml.pinnaclesports.com/pinnaclefeed.aspx?sporttype=Football&sportsubtype=nfl’);
foreach($xml->children() as $event){
echo $event->participants->participant->participant_name . ", ";
echo $event->participants->participant[1]->participant_name . ", ";
echo $event->periods->period->spread->spread_visiting . ", ";
echo $event->periods->period->total->over_adjust . “
”;
}
?>[/php]

Results:
, , ,
, , ,
, , ,
, , ,

I have also tried using file_get_contents, but that fails as well with a PHP error:

[php]<?php
$xmlData = file_get_contents(‘http://xml.pinnaclesports.com/pinnaclefeed.aspx?sporttype=Football&sportsubtype=nfl’);
foreach($xmlData->children() as $event) {
echo $event->participants->participant->participant_name . ", ";
echo $event->participants->participant[1]->participant_name . ", ";
echo $event->periods->period->spread->spread_visiting . ", ";
echo $event->periods->period->total->over_adjust . “
”;
}
?>[/php]

The error:
PHP Fatal error: Call to a member function children() on string in /home/user/public_html/feed.php on line 3

Any help is appreciated!

[php]foreach($xml->children() as $event){[/php]

This starts with an error as the first child in the XML is

<PinnacleFeedTime>1476214164262</PinnacleFeedTime>

[hr]

I’ll give you a nudge in the right direction

[php]$xml = simplexml_load_file(‘http://xml.pinnaclesports.com/pinnaclefeed.aspx?sporttype=Football&sportsubtype=nfl’);
foreach ($xml->events->event as $event)
{
echo $event->league . ’ ’ . $event->event_datetimeGMT;

foreach ($event->participants->participant as $participant)
{
    echo $participant->participant_name;
}

}[/php]

JimL,

Thank you for your help! It was exactly what I needed. Ended up with the following to get it to pull correctly:

[php]<?php
$xml = simplexml_load_file(‘http://xml.pinnaclesports.com/pinnaclefeed.aspx?sporttype=Football&sportsubtype=nfl’);
foreach ($xml->events->event as $event){
echo $event->event_datetimeGMT . ", ";
echo $event->participants->participant->participant_name . " @ ";
echo $event->participants->participant[1]->participant_name . ", ";
echo $event->periods->period->spread->spread_home . ", ";
echo $event->periods->period->total->over_adjust . “
”;
}
?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service