本文介绍了从PHP文件中提取统计数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个jQuery播放器,其顶部有一个统计栏,可从远程xml文件中提取信息.
I have a jQuery player with a stats bar on top that draw information from a remote xml file.
我正在尝试对其进行修改,以从php文件中读取统计信息.
I'm trying to modify it to read stats from a php file.
该php文件从远程服务器中的xspf文件提取统计信息.
That php file draw the stats from a xspf file in the remote server.
我该如何使用以下代码来做到这一点:
How do i go about doing that with the following code:
更新代码:
php文件:
<?php
header('Content-Type:text/xml');
$xml = simplexml_load_file("http://**.**.**.**:8000/live.xspf");
echo '<?xml version="1.0" encoding="UTF-8"?><tracks>';
foreach ($xml->trackList->track as $data) {
$radio = $data->location;
$song = $data->title;
$info = $data->listeners;
echo '<track>
<title>'.$song.'</title>
<listeners>'.$info.'</listeners>
<location>'.$radio.'</location>
</track>';
}
echo '</tracks>';
?>
jQuery代码:
function getCurrentTrack(){
$.get('/player/readerPlayer.php'), function (){
$track = $(data).find('track');
$track.each(function (){
$this = $(this);
var title = $this.find('title').text();
var listenersn = $this.find('listeners').text();
$('.listeners span').html(listenersn);
setTimeout('getCurrentTrack()', 65000);
});
}, 'xml'};
推荐答案
您只需要从PHP文件中输出XML.
You simply need to output XML from your PHP file.
header('Content-Type:text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?><tracks>';
foreach ($xml->trackList->track as $data) {
$radio = $data->location;
$song = $data->title;
$info = $data->listeners;
echo '<track>
<title>'.$song.'</title>
<listeners>'.$info.'</listeners>
<location>'.$radio.'</location>
</track>';
}
echo '</tracks>';
您将需要稍微调整一下js,以便首先获取跟踪对象.
You'll want to adjust the js a little bit to get the track objects first though.
function getCurrentTrack(){
$.get('/player/readerPlayer.php'), function (){
$track = $(data).find('track');
$track.each(function (){
$this = $(this);
var title = $this.find('title').text();
var listenersn = $this.find('listeners').text();
$('.listeners span').html(listenersn);
setTimeout('getCurrentTrack()', 65000);
});
}, 'xml');
}
这篇关于从PHP文件中提取统计数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!