2012-04-25 4 views
2

simplexml_load_file을 사용하여 XML 피드에서 데이터를 추출하려고합니다. 이것은 내가 지금 무엇을 가지고 :simplexml_load_file을 사용하여 XML 피드에서 데이터 추출

<?php 
     $anobii = simplexml_load_file('http://www.anobii.com/rss_shelf?s=01fe251a6c442bbf8a'); 
     foreach ($anobii->entry as $anobiiinfo): 
      $title=$anobiiinfo->rss->channel->item->title; 
      $desc=$anobiiinfo->rss->channel->item->description;  
      echo "<span> ",$title,"</span><br><span> ",$desc,"</span>"; 
     endforeach; 
    ?> 

문제는 내가 스크립트에게 그것을 추출 할 필요가있는 부분 (rss->channel->item->title)을 말할 수있는 권리 구분을 모르는 것입니다.

답변

4

Yous는 개별 항목을 가져 오기 위해 xml 트리 구조를 따라야합니다.

<?php 
     $feedUrl = 'http://www.anobii.com/rss_shelf?s=01fe251a6c442bbf8a'; 
     $rawFeed = file_get_contents($feedUrl); 
     $anobii = new SimpleXmlElement($rawFeed); 

     foreach ($anobii->channel->item as $anobiiinfo): 
      $title=$anobiiinfo->title; 
      $desc=$anobiiinfo->description;  
      echo "<span> ",$title,"</span> <br/> <span> ",$desc,"</span>"; 
     endforeach; 
    ?> 
+0

감사합니다. : D 그것은 작동합니다! 최근 질문 :이 방법 (file_get_contents) 또는 fetch_feed (SimplePie 기반)로 작성된 WordPress를 사용하는 것이 더 빠르고/더 빠릅니까? http://codex.wordpress.org/Function_Reference/fetch_feed 다시 한번 감사드립니다! :) – MultiformeIngegno

+0

피드를 얻기 위해 rs URL을 사용하는 것보다 fetch_feed를 사용하는 것이 더 좋습니다. – Jayaram

관련 문제