Php /Namespace question..

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:group

<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&timestamp=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&timestamp=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-&timestamp=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&timestamp=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!

I really don’t know what you code is doing, but I use namespaces when I write my classes.

Basically namespaces are a way of encapsulating items. They’re great in avoiding conflicts with other classes, methods (functions) or variables.

the basic use of namespace

[php]namespace workspace\foo;[/php]

anything in the directory for that particular item (usually a class)

Here’s a little example of my structure for my namespaces:

website_project\database
website_project\users
website_project\trivia_game
etc…

The nice feature with using namespaces is I don’t have to worry about collisions with methods (functions), variables or even classes having the same name just as long as they are in a separate directory.

to use them on a php page I simply do this
[php]use website_project\database\Database as DB;[/php]

I would hazard a guess that you will have to use the same file directory structure (or change it in the script) that the previous project used in order to get the script to work properly?

[member=57087]Strider64[/member] he’s talking about XML namespaces, something we’re (luckily) seeing less of now that everyone who’s in their right mind has converted to json.

[member=38684]cowboysdude[/member] There should be quite a few resources out there on namespaces, ie
http://www.marcogoncalves.com/2013/07/parsing-media-rss-with-php-simplexml/

Then would that be an outdated script to begin with? Wouldn’t it be better to convert it over to json? Just curious?

P.S. I thought I was up late and probably was part of the reason why I answered the thread. ;D Normally I don’t respond when in doubt. LOL

[member=57087]Strider64[/member] nfl teams web solution loves xml, sadly

Thank you guys… yes converting to json would probably be better but was just trying to learn the namespace thing…

JimL is right… I have an unnatural love of xml LOL But what I’m going to go back convert it to json and go from there…

Yes I will add a cache file to it as well :wink:

Thanks guys!!!

Sponsor our Newsletter | Privacy Policy | Terms of Service