Array question...

Here is my code…

[php]
$feed = file_get_contents(“http://www.dallascowboys.com/rss/video”);
$xml = new SimpleXmlElement($feed);

foreach ($xml->channel->item as $entry){
$date = $entry->pubDate;
$title= $entry->title;
$namespaces = $entry->getNameSpaces(true);
$media = $entry->children($namespaces[‘media’]);
$date = $entry->pubDate;
$title= $entry->title;
$des= $entry->description;
$link = $media->group->content[8]->attributes()->url;
$thumb = $media->group->content[2]->thumbnail[1]->attributes()->url;
$fixedTitle = str_replace("’","",$title);
$fixedDes = str_replace("’’","",$des);
$fixedDate = date(“n-j-Y”, strtotime($date));
$cat= $media->category;
[/php]

It’s only returning 1 from each category… I’m thinking there should be another loop in there somewhere and I’ve tried a few things but cannot get it work…

Here’s the other problem I’m having… this line right here…

$link = $media->group->content[8]->attributes()->url;
  $thumb = $media->group->content[2]->thumbnail[1]->attributes()->url;

Fatal error: Call to a member function attributes() on null in C:\xampp\htdocs\joomla\test\new\test.php on line 31

IF I take the attributes() out I don’t get the link… if I leave it in I get this error but I also get the link…

So there’s two questions for the price of one right there :slight_smile:

Suggestions?

Thanks!

It's only returning 1 from each category... I'm thinking there should be another loop in there somewhere and I've tried a few things but cannot get it work...

The video rss isn’t grouped by category, as far as I can see you print multiple videos from categories where available.

If you want them grouped by category I suggest you use your loop to build a new multi dimensional array of videos like this:

array( 'category1' => [ 0 => [ 'link' => 'link to video one', 'thumb' => 'thumb for video one' ], 1 => [ 'link' => 'link to video two', 'thumb' => 'thumb for video two' ] ], 'category2' => [ // etc )

Reorganizing imported data like this is either way good. You get the structure you need/want in an easily accessible format which you can then use in your templates.

[hr]

Fatal error: Call to a member function attributes() on null in C:\xampp\htdocs\joomla\test\new\test.php on line 31

You are assuming $media->group->content exist and contain X number of elements.

[php] $link = $media->group->content[8]->attributes()->url;
$thumb = $media->group->content[2]->thumbnail[1]->attributes()->url;[/php]

This item does not have 9 items in $media->group->content (arrays are zero indexed so [8] means the ninth item)

<item> <title>Draft Show: LIVE From 2016 NFL Combine - Day 3</title> <link> http://www.dallascowboys.com/video/2016/02/26/draft-show-live-2016-nfl-combine-day-3 </link> <description> The Draft Show broadcasts from day 3 of the NFL Combine in Indy. </description> <guid isPermaLink="false">7b638522-4132-4198-9674-d67bec80ba54</guid> <pubDate>Fri, 26 Feb 2016 18:28:49 -0600</pubDate> <source url="http://www.dallascowboys.com/rss/video">Video</source> <dc:date>Fri, 26 Feb 2016 18:28:49 -0600</dc:date> <media:group> <media:content url="http://prod.video.cowboys.clubs.nfl.com/DAL/videos/dct/video_audio/2016/02-February/draftshow2_022616-32k.mp3" bitrate="64.0" type="video/mp4" duration="3671">...</media:content> <media:content url="http://prod.video.cowboys.clubs.nfl.com/DAL/videos/dct/video_audio/2016/02-February/draftshow2_022616-180k.mp4" bitrate="148.0" type="video/mp4" height="234" width="416" duration="3671">...</media:content> <media:content url="http://prod.video.cowboys.clubs.nfl.com/DAL/videos/dct/video_audio/2016/02-February/draftshow2_022616-320k.mp4" bitrate="298.0" type="video/mp4" height="234" width="416" duration="3671">...</media:content> <media:content url="http://prod.video.cowboys.clubs.nfl.com/DAL/videos/dct/video_audio/2016/02-February/draftshow2_022616-1200k.mp4" bitrate="1134.0" type="video/mp4" height="360" width="640" duration="3671">...</media:content> <media:content url="http://prod.video.cowboys.clubs.nfl.com/DAL/videos/dct/video_audio/2016/02-February/draftshow2_022616-500k.mp4" bitrate="486.0" type="video/mp4" height="360" width="640" duration="3671">...</media:content> <media:content url="http://prod.video.cowboys.clubs.nfl.com/DAL/videos/dct/video_audio/2016/02-February/draftshow2_022616-700k.mp4" bitrate="734.0" type="video/mp4" height="360" width="640" duration="3671">...</media:content> <media:content url="http://prod.video.cowboys.clubs.nfl.com/DAL/videos/dct/video_audio/2016/02-February/draftshow2_022616-2000k.mp4" bitrate="1934.0" type="video/mp4" height="576" width="1024" duration="3671">...</media:content> <media:content url="http://prod.video.cowboys.clubs.nfl.com/DAL/videos/dct/video_audio/2016/02-February/draftshow2_022616-3200k.mp4" bitrate="3104.0" type="video/mp4" height="720" width="1280" duration="3671">...</media:content> </media:group> <media:category>Video - Shows - Draft Show</media:category> </item>

This item doesn’t have $media->group->content at all

<item> <title>NDSU QB Carson Wentz's Full Combine Workout</title> <link> http://www.dallascowboys.com/video/2016/02/27/ndsu-qb-carson-wentzs-full-combine-workout </link> <description> Check out North Dakota State's Carson Wentz's full workout at the 2016 NFL Combine. </description> <guid isPermaLink="false">699367a2-369e-4f91-8d6f-88abf4236ba6</guid> <pubDate>Sat, 27 Feb 2016 15:33:04 -0600</pubDate> <source url="http://www.dallascowboys.com/rss/video">Video</source> <dc:date>Sat, 27 Feb 2016 15:33:04 -0600</dc:date> <media:category>Videos - Draft</media:category> </item>

It seems like the last $media->group->content entry is the highest resolution available, so I’d just select the last one and use that.

ie

[php]$link = ‘’;
$thumb = ‘’;

$mediaCount = count($media->group->content);
if ($mediaCount > 0) {
$index = $mediaCount - 1;
$link = $media->group->content[$index]->attributes()->url;
$thumb = $media->group->content[$index]->thumbnail[1]->attributes()->url;
}[/php]

Well now that’s interesting!! :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service