2013-07-30 2 views
3

내가 내가의디스플레이 XML 출력 - PHP

http://gdata.youtube.com/feeds/api/users/edbassmaster/uploads?orderby=viewCount&max-results=5

이 아래에 링크가있는 결과를 조회수 (조회수)에 의해 YouTube 채널의 동영상의 목록을 얻고 제한 할 수 있습니다 것으로 나타났습니다 물론 일부 XML 피드 코드가 반환됩니다. div에있는 내 웹 사이트에 동영상을 나열하려고합니다. 내가 무엇을 시도했다

: 나는 $xml->title[1]을 시도하는 경우

<?php 
    $list = Array(); 
    //get the xml data from youtube 
    $url = "http://gdata.youtube.com/feeds/api/users/edbassmaster/uploads?orderby=viewCount&max-results=5"; 
    $xml = simplexml_load_file($url); 
    //load up the array $list['title'] = $xml->title[0]; 
    $list['title'] = $xml->title[0]; 
    echo $list['title']; 
?> 

지금까지 그 단지, 나에게 XML 피드의 제목을 제공합니다. 아무것도 반환하지 않습니다. 이 XML 피드를 사용하여 제목을 나열하고 (href) 동영상에 링크 할 수 있습니까? XML 소스, 비디오 제목 및 URL에서 2 가지를 검색하려고합니다.

감사합니다. 이 같은

+1

사용, 후속 항목에 액세스하려면? 저는 문제는 당신이 찾고있는 것이 실제로 자식 요소라는 것입니다. – MisterJ

답변

3

뭔가 다음 문서 루트 아래

<?php 
$url = "http://gdata.youtube.com/feeds/api/users/edbassmaster/uploads?orderby=viewCount&max-results=5"; 
$xml = simplexml_load_file($url); 
foreach($xml->entry as $entry){ 
    echo "Title: ".$entry->title."<br />"; 
    echo "Link :".$entry->link['href']."<br />"; 
} 
?> 
+0

이것은 내 자신의 질문 (http://stackoverflow.com/questions/22880348/cant-access-xml-node-via-xpath-yt-channel-feed)으로 나를 도왔습니다. 나는'$ xml-> entry'가 작동하지만'$ xml-> xpath ('entry')'는 겉으로보기에는 ... (0 노드를 반환합니다) 왜 궁금합니다. – Utkanos

0

첫 번째 타이틀 태그는 하나가 피드의 제목을, constains. 당신은`위해서 var_dump ($ XML을) 만들기`와 결과를 제공하기 위해 시도 할 수 $xml->entry[0]

<?php 
    $list = Array(); 
     // get the xml data from youtube 
     $url = "http://gdata.youtube.com/feeds/api/users/edbassmaster/uploads?orderby=viewCount&max-results=5"; 
     $xml = simplexml_load_file($url); 
     // load up the array $list['entry'] = $xml->title[0]; 
     $entries = $xml->entry; 
//echo preg_replace("feed","fd"file_get_contents($url)); 
    echo $entries[1]->title;//entry[0],entry[1],entry[2]... will work 
     ?>