用PHP中的new替换旧内容

时间:2012-04-12 17:55:10

标签: php jquery

我正在开发视频播放器,其中XML是我的播放列表。这是代码:

$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++;

当用户点击语言时,我想用新内容替换旧内容,所有条目都替换为新条目

1 个答案:

答案 0 :(得分:0)

一个例子

if(isset($_POST["lang"]))
    {
       $lang = $_POST["lang"];
    } else {
       $lang = "eng";
    }
$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 id="playlist">';
        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++;
    }
}

然后在页面上的jQuery中有一个带有语言的选择框,名为#langSelect

$('#langSelect').change( function() {
    var langSelected = $(this).val();

    $("#playlist").load("<?php echo $_SERVER['PHP_SELF']."?uid=".time(); ?> #playlist", {lang: langSelected});
});

要使用此调试尝试:

$('#lang').change( function() {
    var langSelected = $(this).val();
    alert('Selected language: '+langSelected);
    var url = '<?php echo $_SERVER['PHP_SELF']."?uid=".time(); ?>';
    alert('Ajax POST URL is: '+ url);
    $("#playlist").load(url+" #playlist", {lang: langSelected}, function(response, status, xhr) {
            alert(status);
            alert(response);
        }
    });
});