如何多次拨打同一班级?

时间:2014-12-18 03:25:23

标签: javascript php arrays html5 class

如何多次拨打同一个班级?

你好朋友,我正在使用一个着名的用于icecast2的php类,统计显示一个挂载点,可以显示一个挂载点,但现在我想添加其他人来显示朋友无线电列表。

在课程

中留下以下代码
class IceCast {

    var $server     = '';
    var $stats_file = '';
    var $radio_info = array();

    function __construct() {
        //build array to store our radio stats for later use        
        $this->radio_info['server']                = $this->server;
        $this->radio_info['title']                 = 'Offline';
        $this->radio_info['description']           = 'Radio offline';
        $this->radio_info['content_type']          = '';
        $this->radio_info['mount_start']           = '';
        $this->radio_info['bit_rate']              = '';
        $this->radio_info['listeners']             = '';
        $this->radio_info['most_listeners']        = '';
        $this->radio_info['genre']                 = '';
        $this->radio_info['url']                   = '';
        $this->radio_info['now_playing']           = array();
        $this->radio_info['now_playing']['artist'] = 'Unknown';
        $this->radio_info['now_playing']['track']  = 'Unknown';
    }

    function setUrl($url, $file) {
        $this->server               = $url;
        $this->stats_file           = $file;
        $this->radio_info['server'] = $this->server;
    }

    private function fetch() {
        //create a new curl resource
        $ch = curl_init();

        //set url
        curl_setopt($ch, CURLOPT_URL, $this->server . $this->stats_file);

        //return as a string
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        //$output = our stauts.xsl file
        $output = curl_exec($ch);

        //close curl resource to free up system resources
        curl_close($ch);

        return $output;
    }

    function getStatus() {
        $output = $this->fetch();

        //loop through $ouput and sort into our different arrays
        $temp_array = array();

        $search_for = "<td\s[^>]*class=\"streamdata\">(.*)<\/td>";
        $search_td  = array('<td class="streamdata">', '</td>');


        if (preg_match_all("/$search_for/siU", $output, $matches)) {
            foreach ($matches[0] as $match) {
                $to_push = str_replace($search_td, '', $match);
                $to_push = trim($to_push);
                array_push($temp_array, $to_push);
            }
        }

        if (count($temp_array)) {
            //sort our temp array into our ral array
            $this->radio_info['title']          = $temp_array[0];
            $this->radio_info['description']    = $temp_array[1];
            $this->radio_info['content_type']   = $temp_array[2];
            $this->radio_info['mount_start']    = $temp_array[3];
            $this->radio_info['bit_rate']       = $temp_array[4];
            $this->radio_info['listeners']      = $temp_array[5];
            $this->radio_info['most_listeners'] = $temp_array[6];
            $this->radio_info['genre']          = $temp_array[7];
            $this->radio_info['url']            = $temp_array[8];

            if (isset($temp_array[9])) {
                $x                                         = explode(" - ", $temp_array[9]);
                $this->radio_info['now_playing']['artist'] = $x[0];
                $this->radio_info['now_playing']['track']  = $x[1];
            }
        }
        return $this->radio_info;
    }

}

这是我的脚本目前效果很好,现在我想看看如何添加其他mountpoint并在下面显示你的div

<?php

//class
require_once('icecast.php');
$oIceCast = new IceCast();

//change var my radio
$server = 'http://giss.tv:8000';
$file   = '/status.xsl?mount=/radio.mp3';

$oIceCast->setUrl($server, $file);
$status = $oIceCast->getStatus();
$result .= <<<EOF
    <div><strong>Name</strong> {$status['title']}</div>
    <div><strong>Description</strong> {$status['description']}</div>
    <audio controls>
    <source src="http://giss.tv:8000/radio.mp3">
    <!-- This is Where You Enter Your Flash Fall Back -->
    </audio>
    <div><strong>Start</strong> {$status['mount_start']}</div>
    <div><strong>Listeners</strong> {$status['listeners']}</div>
    <div><strong>Max listeners</strong> {$status['most_listeners']}</div>
    <div><strong>Url</strong> {$status['url']}</div>
    <div><strong>Artist</strong> {$status['now_playing']['artist']}</div>
    <div><strong>Track</strong> {$status['now_playing']['track']}</div>
    EOF;
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8" />
    </head>
    <body>
      <div class="container">
        <?= $result ?>
      </div><!--/.container-->
    </body>
    </html>    

我希望你能帮助我或指导 感谢

0 个答案:

没有答案