Thanks very much for the MOD! Very useful.
I have a problem though...
the return from the script shows as:
[8] ?????, ???????????. (1 h.)
[3] ??????????? ?????? (????????) (1 h.)
[2] ???????? ????? (1 h.)
[2] ???????? ? ????????? ??? ???? (1 h.)
I guess this is wrong database encoding return... any idea how to recode the database return into cp1251?
EDIT:
I have found the solution if anybody is interested:
My problem was that the database information was stored in UTF 8 and my site was displayed in Windows 1251...
here is what you need to do to correct those question marks:
in the code above find:
$db = mysql_select_db("your_db_name",$connection) or die("Service temporairly unavailable");
and insert after:
@mysql_query('set character set utf8');
then
replace
echo "[$row[topic_replies_real]] <a href = \"http://www.yourforumdomain.com/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]&view=unread#unread\" target = \"_blank\">$row[topic_title]</a> (".$time_from_last_reply.")<br>";
with
$s = "[$row[topic_replies_real]] <a href = \"http://www.yourforumdomain.com/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]&view=unread#unread\" target = \"_blank\">$row[topic_title]</a> (".$time_from_last_reply.")<br>";
echo iconv('utf-8', 'windows-1251', $s);
that did the trick for me... (sorry I presumed that you have iconv installed with your hosting provider)
in case you do not have it installed, you could use recoding functions available online... here are some samples (i did not check them but they were reported as functional)
function str_encode ($string,$to="iso-8859-9",$from="utf8") {
if($to=="iso-8859-9" && $from=="utf8"){
$str_array = array(
chr(196).chr(177) => chr(253),
chr(196).chr(176) => chr(221),
chr(195).chr(182) => chr(246),
chr(195).chr(150) => chr(214),
chr(195).chr(167) => chr(231),
chr(195).chr(135) => chr(199),
chr(197).chr(159) => chr(254),
chr(197).chr(158) => chr(222),
chr(196).chr(159) => chr(240),
chr(196).chr(158) => chr(208),
chr(195).chr(188) => chr(252),
chr(195).chr(156) => chr(220)
);
return str_replace(array_keys($str_array), array_values($str_array), $string);
}
return $string;
}
function FixEncoding($x){
if(mb_detect_encoding($x)=='UTF-8'){
return $x;
}else{
return utf8_encode($x);
}
}
function cp1251_to_utf8($s)
{
$c209 = chr(209); $c208 = chr(208); $c129 = chr(129);
for($i=0; $i<strlen($s); $i++) {
$c=ord($s[$i]);
if ($c>=192 and $c<=239) $t.=$c208.chr($c-48);
elseif ($c>239) $t.=$c209.chr($c-112);
elseif ($c==184) $t.=$c209.$c209;
elseif ($c==168) $t.=$c208.$c129;
else $t.=$s[$i];
}
return $t;
}
function utf8_to_cp1251($s)
{
for ($c=0;$c<strlen($s);$c++)
{
$i=ord($s[$c]);
if ($i<=127) $out.=$s[$c];
if ($byte2){
$new_c2=($c1&3)*64+($i&63);
$new_c1=($c1>>2)&5;
$new_i=$new_c1*256+$new_c2;
if ($new_i==1025){
$out_i=168;
} else {
if ($new_i==1105){
$out_i=184;
} else {
$out_i=$new_i-848;
}
}
$out.=chr($out_i);
$byte2=false;
}
if (($i>>5)==6) {
$c1=$i;
$byte2=true;
}
}
return $out;
}
so if you will use functions then your last line will look like this:
echo utf8_to_cp1251($s);
I hope this will save lots of research for people )))