| Есть проблема с кодировкой текста.
У нас во внутренней сети стоит Shoutcast радио, и для пользователей есть отдельная страница с нормальным оформлением. Но дело в том что текст на странице выставляется посредством загрузки со страницы Shoutcast, латиница в этом случае отображается нормально, а вот с кирилицей проблема.
Если кто сталкивался с данной проблемой и знает решение - подскажите пожалуйста как решить.
Вот текст скрипта, который отвечает за вывод информации:
---------------------------------------------------------------------------------------------
<?
///////////////////////////////////////////////////////////////////////////////////////////////
// Just a little bit about this script.
// Part 1 Written by: T. Stanley
// Part 2 add-ons Written by: ST. JOHN
// Connection stuff from Jay Krivanek's and Oddsock's SHOUTout script.
// First feel free to edit it to suit your needs.
// This script does all that T. Peppers does (however it is probably a bit slower
// but it works w/o the XML stuff just pure PHP) and also retrieves the bitrate
// (if stream is up) and whether there is a source (DSP connected with DNAS).
// It relies heavily on the assumption that 7.html, index.html and XML page will not change.
// Currently works with DNAS 1.8.0 (haven't tested older versions).
// If you upgrade the DNAS and it breaks it is due to the fact that Nullsoft has changed
// the data on 7.html, index.html and XML page and the ereg_replace and explode will need
// to be tweaked.
// Right now it is setup to print out every variable it gets.
// Song data (titles and playedats)is recursive so it can get up to 20 (if set in DNAS) as
// well a unlimited listener info (IP, etc.)
// It is suggested that any variables you don't need you comment out or delete the extraction
// of the data.
// Arrays (song, playedats, etc.) start with 0. (i.e. song[0] = currently playing song)
// Thanks to Ari for the explanation of 7.html on the SHOUTcast listserv (I was lurking)
// Run the srcipt as is (after changing host, port, password) for a list of variables printed
// out (listnener data and song history will not show up unless there is data for them).
// Contacts:
// tom@shoutclub.com
// dstjohn@mediacast1.com
// Notes:
// Very Important >> Uncomment(take away the forward slashes //)
// all the echo statements to get a full list of all the variables,
// if you dont know what im talking about, then stop right here and go learn php
// http://www.php.net
// http://www.thickbook.com << very resourcefull for beginners
///////////////////////////////////////////////////////////////////////////////////////////////
include ("config.php");
$listenlink = 'http://'.$host.':'.$port.'/listen.pls'; //make link to stream
$fp = fsockopen("$host", $port, &$errno, &$errstr, 30); //open connection
if(!$fp) {
$success=2; //set if no connection
}
if($success!=2){ //if connection
fputs($fp,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible) \r\n\r\n"); //get 7.html
while(!feof($fp)) {
$page .= fgets($fp, 1000);
}
fclose($fp); //close connection
$page = ereg_replace(".*<body>", "", $page); //extract data
$page = ereg_replace("</body>.*", ",", $page); //extract data
$numbers = explode(",",$page); //extract data
$currentlisteners=$numbers[0]; //set variable
$connected=$numbers[1]; //set variable
if($connected==1) //if DSP is connected
$wordconnected="yes"; //set variable
else //if no DSP connection
$wordconnected="no"; //set variable
$peaklisteners=$numbers[2]; //set variable
$maxlisteners=$numbers[3]; //set variable
$reportedlisteners=$numbers[4]; //set variable
##Stuff printing out to screen may want to shut off.##
// echo('$listenlink = '.$listenlink.'<BR>');
// echo('$reportedlisteners = '.$reportedlisteners.'<BR>');
// echo('$maxlisteners = '.$maxlisteners.'<BR>');
// echo('$peaklisteners = '.$peaklisteners.'<BR>');
// echo('$connected = '.$connected.' <BR>');
// echo('$wordconnection = '.$wordconnected.'<BR>');
// echo('$currentlisteners = '.$currentlisteners.'<BR>');
##Okay stop commenting stuff out now.##
}
if($connected==1){ //only do if DSP is connected
$fp = fsockopen("$host", $port, &$errno, &$errstr, 30); //open connection
if(!$fp) { //if no connection
$success1=2; //dummy variable to see if successful connect
}
if($success1!=2){ //only do if connected
fputs($fp,"GET /index.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible) \r\n\r\n"); //get index.html
while(!feof($fp)) {
$page .= fgets($fp, 1000);
}
$pageed = ereg_replace(".*Stream is up at ", "", $page); //extract data
$bitrate = ereg_replace(" kbps.*", "", $pageed); //extract data
fclose($fp); //close connection
##Print out bitrate.##
//echo('$bitrate = '.$bitrate.' <BR>');
##You know the drill stop here.##
}
}
$fp = fsockopen("$host", $port, &$errno, &$errstr, 30); //open connection yet again
if(!$fp) { //if connection
$success2=2;
}
if($success2!=2){ //if connected
fputs($fp,"GET /admin.cgi?pass=$password&mode=viewxml HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get XML page
while(!feof($fp)) {
$page .= fgets($fp, 1000);
}
$loop = array("AVERAGETIME", "SERVERGENRE", "SERVERURL", "SERVERTITLE", "SONGTITLE", "SONGURL", "IRC", "ICQ", "AIM", "WEBHITS", "STREAMHITS", "INDEX", "LISTEN", "PALM7",
"LOGIN", "LOGINFAIL", "PLAYED", "COOKIE", "ADMIN", "UPDINFO", "KICKSRC", "KICKDST", "UNBANDST", "BANDST", "VIEWBAN", "UNRIPDST", "VIEWRIP", "VIEWXML",
"VIEWLOG", "INVALID"); //define all the variables to get (delte any ones you don't want)
$y=0; //dummy variable for while loop
while($loop[$y]!=''){ //while there are things in loop
$pageed = ereg_replace(".*<$loop[$y]>", "", $page); // extract data
$phpname = strtolower($loop[$y]); //make names in loop lowercase for variable names
$$phpname = ereg_replace("</$loop[$y]>.*", "", $pageed); //finish extracting data
if($loop[$y]==SERVERGENRE || $loop[$y]==SERVERTITLE || $loop[$y]==SONGTITLE) //if for code clean-up (if you have problems with variables with URL encoding (i.e. %20 for space put them in this loop)
$$phpname = urldecode($$phpname); // replace URL code with regular text (i.e. %20 = space)
##More stuff that prints##
//echo ('$'.$phpname.' = '.$$phpname.' <BR>');
##Stop here. Your server will be upset if you comment out the next line of code ($y++;).##
$y++; //update dummy variable for while loop
}
$pageed = ereg_replace(".*<SONGHISTORY>", "", $page); //extract data
$pageed = ereg_replace("<SONGHISTORY>.*", "", $pageed); //extract data
$songatime = explode("<SONG>", $pageed); //break data down for each song
$r=1; //dummy variable
while($songatime[$r]!=""){ //while loop for each song
$t=$r-1; //correction for first value in array from explode is worthless
$playedat[$t] = ereg_replace(".*<PLAYEDAT>", "", $songatime[$r]); // extract data
$playedat[$t] = ereg_replace("</PLAYEDAT>.*", "", $playedat[$t]); //extract data
$song[$t] = ereg_replace(".*<TITLE>", "", $songatime[$r]); //extract data
$song[$t] = ereg_replace("</TITLE>.*", "", $song[$t]); //extract data
$song[$t] = urldecode($song[$t]); //cleans-up the URL code thing again
##Yet even more crap that gets printed out.##
//echo ('$song['.$t.'] = '.$song[$t].' <BR>$playedat['.$t.'] = '.$playedat[$t].' <BR>');
##Same as last time. Unhappy servers tend to hurt people.##
$r++; //update loop variable
}
$pageed = ereg_replace(".*<LISTENERS>", "", $page); //extract data
$pageed = ereg_replace("</LISTENERS>.*", "", $pageed); //extract data
$listeninfo = explode("<LISTENER>", $pageed); //break apart data
$r=1; //dummy loop variable
while($listeninfo[$r]!=""){ //while loop for extraction
$t=$r-1; //correction for first value in array from explode is worthless
$hostname[$t] = ereg_replace(".*<HOSTNAME>", "", $listeninfo[$r]); //extract data
$hostname[$t] = ereg_replace("</HOSTNAME>.*", "", $hostname[$t]); //extract data
$useragent[$t] = ereg_replace(".*<USERAGENT>", "", $listeninfo[$r]); //extract data
$useragent[$t] = ereg_replace("</USERAGENT>.*", "", $useragent[$t]); //extract data
$underruns[$t] = ereg_replace(".*<UNDERRUNS>", "", $listeninfo[$r]); //extract data
$underruns[$t] = ereg_replace("</UNDERRUNS>.*", "", $underruns[$t]); //extract data
$connecttime[$t] = ereg_replace(".*<CONNECTTIME>", "", $listeninfo[$r]); //extract data
$connecttime[$t] = ereg_replace("</CONNECTTIME>.*", "", $connecttime[$t]); //extract data
##Yet even more crap that gets printed out.##
// echo ('$hostname['.$t.'] = '.$hostname[$t].' <BR>$useragent['.$t.'] = '.$useragent[$t].' <BR>$underruns['.$t.'] = '.$underruns[$t].' <BR>$connecttime['.$t.'] = '.$connecttime[$t].'<BR>');
##STOP. Just think that was the last set of echos you have to comment out.##
$r++; //update loop variable
}
fclose($fp); //close connection
}
$password=changeme //Leave this. It writes over real value so if someone were to use
//include to get this page they cannot use echo $password to get your
//password. There is probably a better way to do this but I can't code.
?>
---------------------------------------------------------------------------------- | |