Welkom, Gast. Je bent niet ingelogd.

Nowplaying in PHP

JoeyK
Geplaatst op: 02 Mar 2008, 14:30
PimpCoins: 0
💸+
Bewerken Quote

Hey,

Ik heb deze code hij moet het nummer laten zien wat de server afspeelt maar ik krijgt

Server is up and currently public ofzo..

dit is de code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php 
################################## 
##### This document contains a class that will allow you to easily extract data from online radiostations 
##### Also, an example is provided at the bottom 
##### 
##### This class has been written by Martijn Korse and may be freely used, but only for non-profit purposes 
##### When in doubt, please contact me : marty[at]excudo[dot]net 
##### http://start.excudo.net 
##### 
##### (ps: a handwritten version of the stripos() function has also been included in this document, for those 
##### without PHP 5) 
################################## 


# 
# The Class 
# 
class Radio
 { 
    var $fields; 
    var $very_first_str; 

    function Radio($array=array()) 
    { 
        $this->setFields($array); 
        $this->setOffset("Current Stream Information"); 
    } 

    function setFields($array) 
    { 
        $this->fields = $array; 
    } 
    function setOffset($string) 
    { 
        $this->very_first_str = $string; 
    } 

    function getData($url, $port, $display_array=null, $very_first_str=null) 
    { 
        if (!isset($display_array)) 
            $display_array = $this->fields; 
        if (!isset($very_first_str)) 
            $very_first_str = $this->very_first_str; 

        $domain = (substr($url, 0, 7) == "http://87.212.162.42") ? substr($url, 7) : $url; 
        
         // opening a connection and reading the contents 
        if (@$fp = fsockopen($domain, $port, $errno, $errstr, 2)) 
        { 
            $contents = ""; 
            fputs($fp, "GET / HTTP/1.1\r\n". 
                "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\r\n". 
                "Host: ".$domain."\r\n\r\n"); 
            while (!feof($fp)) 
            { 
                $contents .= fgets($fp, 256); 
            } 
            fclose ($fp); 

             // parsing the contents 
            foreach ($display_array AS $key => $item) 
            { 
                $very_first_pos    = stripos($contents, $very_first_str); 
                $first_pos    = stripos($contents, $item, $very_first_pos); 
                $line_start    = strpos($contents, "<td>", $first_pos); 
                $line_end    = strpos($contents, "</td>", $line_start) + 4; 
                $difference    = $line_end - $line_start; 
                $line        = substr($contents, $line_start, $difference); 
                $data[$key]    = strip_tags($line); 
            } 
            return $data; 
        } 
        else 
        { 
            return $errstr." (".$errno.")"; 
        } 
    } 
} 

 // schaamteloos van php.net gekopieerd 
if (!function_exists("stripos")) 
{ 
    function stripos($haystack, $needle, $offset=0) 
    { 
        return strpos(strtoupper($haystack), strtoupper($needle), $offset); 
    } 
} 

# 
# The example 
# 

 /****** 
  * $display_array determines the data that will be displayed 
  * ============== 
  * Posibilities: 
  * -------------- 
  * - Server Status 
  * - Stream Status 
  * - Listener Peak 
  * - Average Listen Time 
  * - Stream Title 
  * - Content Type 
  * - Stream Genre 
  * - Stream URL 
  * - Stream AIM 
  * - Stream IRC 
  * - Current Song 
  ***/ 

$display_array = array("Current Song"); 

$radio = new Radio($display_array); 

$data_array = $radio->getData("http://87.212.162.42", 8000); 

if (is_array($data_array)) 
{ 
    foreach ($display_array AS $i => $text) 
    { 
        if ($text == "http://87.212.162.42:8000") {
            $datastring = "<a href="".$data_array[$i]."" target="_blank">".$data_array[$i]."</a>"; 
        } else {
        
        
        $datastring = $data_array[$i]; 
    
       echo $text; 
       echo $datastring; 
      }
    } 
} 

?>

Wie kan me hierbij helpen?

🤷‍♂️
Nog geen reacties, wees de eerste!
📫

Nieuw privébericht

🔥

Registreren


Login