2013-10-07 2 views
1

audiojs 플러그인을 사용하여 HTML5 재생 목록을 만들려고합니다.xml 파일에서 html5 재생 목록 만들기

<playlist> 
    <item> 
    <title>bla bla bla</title> 
    <artist>Big Bla</artist> 
    <path>/mp3/bla-bla-bla.mp3</path> 
    </item> 
    <item> 
    <title>bla bla blab</title> 
    <artist>lil Big Bla</artist> 
    <path>/mp3/bla-bla-bla.mp3</path> 
    </item> 
</playlist> 

이 내 .PHP 파일입니다 : 그것은 사용자 정의 CMS에 의해 관리되는대로 내 재생 목록이 외부 XML 파일에

 <div id="player-holder"> 
      <audio preload></audio> 
      <ul> 
       <li> 
        <a data-src="track path" href="#">title</a> 
       </li> 
       <li> 
        <a data-src="track path" href="#">title</a> 
       </li> 
       <li> 
        <a data-src="track path" href="#">title</a> 
       </li> 
      </ul> 
     </div> 

나는 XML 문서에서 노래 경로를 얻을 필요 "data-src"속성에 추가하고 노래 제목을 가져 와서 앵커 링크로 표시하십시오.

약 6 개의 트랙이 재생 목록에 포함되므로 XML의 각 항목을 반복하고 자체 목록 항목에 해당 데이터를 출력해야합니다.

답변

0

PHP에 내장 된 XML 구문 분석기가 있습니다.

http://php.net/manual/en/book.xml.php

편집이 : 당신의 구조가 미리 알려진 경우 LIB는

http://www.php.net/manual/en/simplexml.examples-basic.php는 CURL 또는 표준 file_get_contents() 전화뿐만 아니라, 그 사용 ... 좀 더 쉽게 작동 할 수 있습니다, 당신은해야한다 서버가 XML을 검색하고이를 트리 구조로 구문 분석하고 결과를 반복하여 표시 할 HTML을 생성 할 수 있습니다.

<?php 
$playlistXML = file_get_contents('http://whatever.cms.com/playlist.xml'); 
$playlist = new SimpleXMLElement($playlistXML); 
foreach($playlist->item as $song) { ?> 
    <a href="<?= $song->path; ?>"><?= $song->title.' - '.$song->artist; ?> </a> 
<?php } ?> 
0

나는 SimpleXML에 투표 할 것입니다.

서버에서 XML을로드하고 SimpleXML을 사용하여 구문 분석 한 다음 목록의 각 노래를 반복하여 제공된 제목과 아티스트를 사용하여 템플릿 목록 항목을 반복합니다.

<?php 
/* first load the XML and create the containing div */ 
    $playlistRawXML = file_get_contents('http://example.com/path/to/playlist.xml'); 

    try { 
     $playlist = new SimpleXMLElement($playlistRawXML); 
    } catch (Exception $e) { 
     /* if SimpleXML can't parse the file, it'll throw an exception */ 
     echo "XML parsing error"; 
     var_dump($e); 
     exit; 
    } 
?> 
<div id="player-holder"> 
    <audio preload></audio> 
    <ul> 

<?php 
    /* then, for each song in the playlist, render a list item: */ 

    foreach($playlist->item as $song) { 
     echo '<li><a data-src="' . $song->path . '" href="#">' . $song->title . ' (' . $song->artist . ')</a></li>'; 
    } 

    /* and then end the list, div, etc.: */ 
?> 

    </ul> 
</div> 
관련 문제