TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-03-2008, 06:15 PM   #1 (permalink)
The Wanderer
Newcomer 
 
Join Date: Feb 2008
Posts: 6
Thanks: 2
pabin is on a distinguished road
Default PHP XML thumb

I am having problem with xml and php, well i am trying to display the thumbnail from xml file. The xml file has following line.

Code:
<media:thumbnail width="66" height="49" url="link of the page"/>
well i can get the title and link but not able to get the image. I have tried various way but still no good result.


Code:
$xml = new SimpleXMLElement("url of file");
//loop to repeat

$img = $xml->channel->item[$i]['media:thumbnail']
;

But still the image wont display.Could somebody help me out.
pabin is offline  
Reply With Quote
Old 11-03-2008, 07:21 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
Salathe is on a distinguished road
Default

SimpleXML isn't quite so simple when it comes to namespaced items. (Using the full url for the media namespace.)

PHP Code:
// Grab media: nodes for this item
$media $xml->channel->item[$i]->children('http://search.yahoo.com/mrss/');

// Grab media:thumbnail node
$thumbnail $media->thumbnail->attributes();

// Grab media:thumbnail url attribute
$img = (string) $thumbnail->url
Alternatively, thanks to chaining we can tidy things up a bit:
PHP Code:
$img = (string) $item->children('http://search.yahoo.com/mrss/')->thumbnail->attributes()->url
I hope that provides a starting point.

P.S. As of PHP 5.2.0 you can alternatively use the namespace label rather than the uri. E.g. $item->children('media', TRUE)->thumbnail…

Last edited by Salathe : 05-29-2009 at 09:07 AM.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
zeuf (05-29-2009)
Old 05-29-2009, 04:23 AM   #3 (permalink)
The Visitor
 
zeuf's Avatar
 
Join Date: May 2009
Location: Paris
Posts: 4
Thanks: 1
zeuf is on a distinguished road
Default

Hi Salathe,

Thank you for your clear answer... It helps me a lot !

Wish you the best.

Truely,
zeuf is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 05:04 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design