0
<?php 
    $url = 'https://picasaweb.google.com/data/feed/api/user/114098057261214889617/albumid/5282805114683350385?alt=rss&kind=photo&max-results=1';
    $session = curl_init($url); 
    curl_setopt($session, CURLOPT_HEADER, false); 
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true); 
    $response = curl_exec($session); 
    curl_close($session); 
    $xml = simplexml_load_string($response);
    $gphoto = $xml->channel->item->children('http://schemas.google.com/photos/2007');
    echo $gphoto->width;//nothing return  
    ?>

How to get picasa rss image width and height? Thanks.

the xml tree here:

  <?xml version="1.0" encoding="UTF-8" ?> 
- <rss xmlns:exif="http://schemas.google.com/photos/exif/2007" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gphoto="http://schemas.google.com/photos/2007" xmlns:media="http://search.yahoo.com/mrss/" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:gml="http://www.opengis.net/gml" xmlns:georss="http://www.georss.org/georss" version="2.0">
- <channel>
 - <item>
...
  <gphoto:width>1280</gphoto:width> 
  <gphoto:height>960</gphoto:height> 
...
</item>
</channel>
</rss>
yuli chika
  • 9,053
  • 20
  • 75
  • 122
  • running your code with PHP 5.3.3 results in `1280` output for me – brian_d Aug 03 '11 at 20:19
  • as well, `phpinfo()` output shows that I have `libxml2 2.7.8` with `XML namespace support active` for what it is worth – brian_d Aug 03 '11 at 20:21
  • @brian_d, no libxml2 2.7.8, so I should download one. – yuli chika Aug 03 '11 at 20:27
  • 1
    I do not actually know why it works without modification for me and not for yours. Just letting you know a PHP version that seems to be working. My simplexml revision is 299424. Best of luck : ) – brian_d Aug 03 '11 at 20:38
  • SimpleXML Revision: 272374, libxml 2.7.3, now I am update my php version becarefully. – yuli chika Aug 03 '11 at 20:54
  • Aight, works with libxml 2.7.8 here, simpexml revision 308262 – Wrikken Aug 03 '11 at 21:11
  • possible duplicate of [Read a namespaced attribute from a SimpleXmlElement (imported from XMLReader)](http://stackoverflow.com/questions/6001784/read-a-namespaced-attribute-from-a-simplexmlelement-imported-from-xmlreader) – Gordon Aug 03 '11 at 21:45
  • possible duplicate of [SimpleXml working with XML containing namespaces](http://stackoverflow.com/questions/2014835/simplexml-working-with-xml-containing-namespaces) – Gordon Aug 03 '11 at 21:46
  • @Gordon: we seem to have passed the default XML namespace points: for some reason `children()` doesn't work for the OP... – Wrikken Aug 03 '11 at 22:10

2 Answers2

3
$width  = $xml->channel->item->children('gphoto',true)->width;
$height = $xml->channel->item->children('gphoto',true)->height;
Wrikken
  • 69,272
  • 8
  • 97
  • 136
  • Hm, _works here_ ... Then again, your _original_ code works here I see now. – Wrikken Aug 03 '11 at 20:13
  • I can get `echo $xml->channel->managingEditor;` but still not get `echo $xml->channel->item[0]->children('gphoto',true)->height;` i use php 5.2.11. – yuli chika Aug 03 '11 at 20:16
  • What does `$gphoto->asXML()` give you? And/or `$xml->channel->item->asXML();`? – Wrikken Aug 03 '11 at 20:21
  • long long thing `http://picasaweb.google.com/data/entry/base/user/114098057261214889617/albumid/5282805114683350385/photoid/` ... `http://picasaweb.google.com/114098057261214889617/Florence#5282805570581096802Virginia LuporiView of Florence & the Duomo from the Piazzale Michaelangolo Florence ItalyDSC07484_2.JPG43.75279 11.236901943.77279 11.29290243.76279 11.264902` – yuli chika Aug 03 '11 at 20:25
  • I am now tring `XmlReader Class`. Thanks to all. – yuli chika Aug 03 '11 at 20:59
  • @Yuli chika: I meant the _source_, not how it looks in a browser... And as said, works perfectly here, I don't believe you should need `XMLReader` (I'd go `DOM` before that), but the best of luck to you. – Wrikken Aug 03 '11 at 21:01
  • @Yuli chika It is much easier to use SimpleXML or DOM. If you can upgrade your PHP version or get your webhost to do it, that is must easier than learning XMLReader – brian_d Aug 03 '11 at 21:05
-2

I find it easier to remove the namespaces when dealing with the google API feeds.

$response = str_replace('gphoto:', '', $response);
Josh
  • 932
  • 7
  • 12
  • 2
    It will make life only harder if you ever have to deal with real XML manipulation. A hard vote down because I consider this a very bad practice to get into. It will in this particular case of course 'work', but is prone to breakage. – Wrikken Aug 03 '11 at 20:19