4images Forum & Community
4images Issues / Ausgaben => Discussion & Troubleshooting => Topic started by: Yan on December 19, 2009, 01:34:21 PM
-
I have a problem. My Mysql server use default character utf-8, and I use the cp1251 character
How do I prescribe in a script, equating to character cp1251?
This example for the forum vb
mysql_query ("set character_set_client='cp1251'");
mysql_query ("set character_set_results='cp1251'");
mysql_query ("set collation_connection='cp1251_general_ci'");
P.S sorry for my bad English :oops:
-
Try a function shown at the end of this post
http://www.4homepages.de/forum/index.php?topic=26465.msg143800#msg143800
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;
}