2012-04-07 85 views
-1

我正在開發其中XML是我的播放列表的視頻播放器。 這裏是代碼:在PHP中用新的替換舊的div內容

$crxml=file_get_contents('http://spoti.com/latest.xml/?lang=en');  
$rss=new SimpleXMLElement($crxml); 
$playlistitem=1; 
    foreach($rss->channel->item as $post) 
    { 
    if($playlistitem<=8) 
    {  
    echo '<ul>'; 
    echo '<li class="xtitle">'.$post->title.'</li>'; 
    echo '<li class="xdesc">'.$post->description.'</li>';  
    $dc=$post->children('http://search.yahoo.com/mrss/'); 
    echo '<li class="xthumb">'.$dc->thumbnail->attributes()->url.'</li>'; 
    echo '<li class="xpreview">'.$dc->thumbnail->attributes()->url.'</li>'; 
    echo '<li class="xsources_mp4">'.$dc->content->attributes()->url.'</li>'; 
    $dc->content->attributes()->url=preg_replace('/.mp4/','.webm',$dc->content-attributes()->url); 
    echo '<li class="xsources_webm">'.$dc->content->attributes()->url.'</li>'; 
    echo '</ul>'; 
    $playlistitem++; 
    } 

我想,以取代舊的內容與新內容時對語言用戶點擊的所有條目新條目

回答

0
$('#lang').change(function() { 
$.post('player_xml.php', {lang: $(this).val()}, function(data) { 
    $('#xplaylist').html(data); 

     $lang =strtolower(issset($_GET['lang']) ? $_GET['lang']:'en'); 
    $crxml=file_get_contents('http://spoti.com/latest.xml/?lang='. $lang); 
    $rss=new SimpleXMLElement($crxml); 
     $playlistitem=1; 
     foreach($rss->channel->item as $post)  
    if($playlistitem<=8)   
echo '<ul>'; 
echo '<li class="xtitle">'.$post->title.'</li>'; 
echo '<li class="xdesc">'.$post->description.'</li>';  
$dc=$post->children('http://search.yahoo.com/mrss/'); 
echo '<li class="xthumb">'.$dc->thumbnail->attributes()->url.'</li>'; 
echo '<li class="xpreview">'.$dc->thumbnail->attributes()->url.'</li>'; 
echo '<li class="xsources_mp4">'.$dc->content->attributes()->url.'</li>'; 
$dc->content->attributes()->url=preg_replace('/.mp4/','.webm',$dc->content-attributes()->url); 
echo '<li class="xsources_webm">'.$dc->content->attributes()->url.'</li>'; 
echo '</ul>'; 
$playlistitem++; 
1

如果我沒有記錯的更換,一旦頁面加載, PHP已經完成了它的工作,並且不能再做任何事情。
如果你想一次在頁面加載改變的東西,你應該嘗試的東西像jQuery:

<script> 
    $("Class_or_ID_of_button").click(function() { 
    $('div_or_span_to_change').html('this will appear once you click the button'); 
}); 
</script> 

我不是專家了,所以我需要更多的信息,給你一個確切的代碼幫助你...希望這有助於!


http://api.jquery.com/click/
http://api.jquery.com/html/

+0

,如果你想要的onclick改變其內容爲其它XML值,我建議每個語言加載到一個不同的變量,因此,在jQuery的你可以只使用。PHP .. 例如 '代碼 ' – 2012-04-07 04:12:00