XML : Get value from Google custom search rss with PHP

I have a Google Custom search RSS that gives me this xml (simplified):

  <?xml version="1.0" encoding="UTF-8"?>     <title>Google Custom Search - the rocky horror picture show 1975</title>     <entry gd:kind="customsearch#result">     <id>http://www.imdb.com/title/tt0073629/</id>     <cse:PageMap>       <cse:DataObject type="metatags">         <cse:Attribute name="og:image" value="http://URLtoAnImage.com/image.jpg"/>  <!-- and so on... -->    

I managed to get the value of "id" (http://www.imdb.com/title/tt0073629/) into an array ($item) with this php:

  $rss = new DOMDocument();  $rss->load($myRSS); // the RSS URL    $feed = array();    foreach ($rss->getElementsByTagName('entry') as $node) {      $item = array (          'link' => $node->getElementsByTagName('id')->item(0)->nodeValue,          );      array_push($feed, $item);      break; //break because I only want the first search result (entry)  }    

Can someone please help me get the "og:image" value into the same array with the same php code?

Or do I need a different php code?

No comments:

Post a Comment