So here I am on my next leg of learning… the dreaded namespace… so far for a starter it’s been all the nightmare I thought it might be :o
So I have this code… no I didn’t write it but I have ‘adjusted’ it to work with another project that I did and it worked out well so I thought ok let me try this…
This one… has me totally stumped…
Here’s a snippet of the xml…
<?xml version="1.0" encoding="utf-8" ?> Video Recent videos http://www.dallascowboys.com/ en Fri, 12 Feb 2016 19:54:30 -0600 Fri, 12 Feb 2016 19:55:47 -0600 Henry Sroka Explica El Proceso De La Agencia Libre http://www.dallascowboys.com/video/2016/02/12/henry-sroka-explica-el-proceso-de-la-agencia-libre 3850b5f6-473b-4b30-a41a-5f978d7bf651 Fri, 12 Feb 2016 19:54:30 -0600 Video Fri, 12 Feb 2016 19:54:30 -0600<media:content url=“http://prod.video.cowboys.clubs.nfl.com/DAL/videos/dct/video_audio/2016/02-February/Somos_Henry-32k.mp3” bitrate=“64.0” type=“video/mp4” duration=“197”>
<media:thumbnail url=“http://www.dallascowboys.com/sites/dallascowboys.com/files/styles/rss_thumb/public/_video_thumbnails/screen_shot_2016-02-12_at_7.44.20_pm.png?itok=p2bYXnyk×tamp=0” width=“130” height=“80” />
<media:thumbnail url=“http://www.dallascowboys.com/sites/dallascowboys.com/files/styles/rss_small/public/_video_thumbnails/screen_shot_2016-02-12_at_7.44.20_pm.png?itok=cunO-aex×tamp=0” width=“280” height=“187” />
<media:thumbnail url=“http://www.dallascowboys.com/sites/dallascowboys.com/files/styles/rss_medium/public/_video_thumbnails/screen_shot_2016-02-12_at_7.44.20_pm.png?itok=IZ-Y943-×tamp=1455419174” width=“540” height=“360” />
<media:thumbnail url=“http://www.dallascowboys.com/sites/dallascowboys.com/files/styles/rss_large/public/_video_thumbnails/screen_shot_2016-02-12_at_7.44.20_pm.png?itok=ph4C_mZj×tamp=0” width=“1000” height=“1000” />
</media:content><media:content url=“http://prod.video.cowboys.clubs.nfl.com/DAL/videos/dct/video_audio/2016/02-February/Somos_Henry-500k.mp4” bitrate=“486.0” type=“video/mp4” height=“360” width=“640” duration=“197”>
media:description640x360</media:description>
Here’s the code I’m using to access this…
$xml = simplexml_load_file('http://www.dallascowboys.com/rss/video');
$namespaces = $xml->getNamespaces(true); // get namespaces
$items = array();
foreach ($xml->channel->item as $item) {
$tmp = new stdClass();
$tmp->title = trim((string) $item->title);
$tmp->link = trim((string) $item->link);
// etc...
// now for the data in the media:group
//
$media_group = $item->children($namespaces['media'])->group;
$tmp->media_url = trim((string)
$media_group->children($namespaces['media'])->content->attributes()->url);
//$tmp->media_thumbnail = trim((string)
// $media_group->children($namespaces['media'])->content->thumbnail[0]->attributes()->url);
//$tmp->media_description = trim((string)
//$media_group->children($namespaces['media'])->content->description);
echo "<pre>";
//print_r($tmp->media_description);
print_r($tmp->media_url);
echo "</pre>";
}
I have the media_description and media_thumbnail working… I can get the media_url to work but it’s only sending back the url to the mp3 and what I’m trying to get to is the mp4…
So two questions…
How far am I off in the media_url code to actually picking up the mp4?
Second… the code is only returning 9 items there are many more… so that’s stumping me too…
if I haven’t posted enough info please let me know!
Thank you all!