Recent Topics

1 Oct 03, 2009 18:09    

hi there,

i know that others have already addressed this issue in other posts on this forum, but i'm finding it really difficult to make sense of it all and i'm sure it's not nearly as complicated as it looks.

so, could some lovely person out there please tell me in really simple language how i can get chinese characters to show up properly in my blog posts?

as always, thanks in advance!

jessie

2 Oct 12, 2009 15:36

BACK-UP your files and Database FIRST!!

1) Open your /conf/_locales.php file

do this change:
[php]$db_config['connection_charset'] = 'utf8';[/code]

2) Go to your phpMyAdmin and change your MySQL's default to "unicode_ci_utf8" or something similar

3) Change your b2evo DB to unicode_ci_utf8 as well (or something similar)

4) Then run this script: (save it in a file first, then upload)


<?php
$conn = mysql_connect("localhost", "DBUSERNAME", "DBPASSWORD");

$printonly=true; //change this to false to alter on the fly
$charset="utf8";
$collate="utf8_unicode_ci";
$altertablecharset=true;
$alterdatabasecharser=true;

function PMA_getDbCollation($db)
{
 $sq='SHOW CREATE DATABASE `'.$db.'`;';
 $res = mysql_query($sq);
 if(!$res) echo "\n\n".$sq."\n".mysql_error()."\n\n"; else
 if($row = mysql_fetch_assoc($res))
 {
  $tokenized = @explode(' ', $row[1]);
  unset($row, $res, $sql_query);
  for ($i = 1; $i + 3 < count($tokenized); $i++)
  {
   if ($tokenized[$i] == 'DEFAULT' && $tokenized[$i + 1] == 'CHARACTER' && $tokenized[$i + 2] == 'SET')
   {
    if (isset($tokenized[$i + 5]) && $tokenized[$i + 4] == 'COLLATE')
    {
     return array($tokenized [$i + 3],$tokenized[$i + 5]); // We found the collation!
    }
    else
    {
     return array($tokenized [$i + 3]);
    }
   }
  }
 }
 return '';
}

?>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8<? //remember to change it if needed ?>" />
<xmp>
<?php

$rs2 = mysql_query("SHOW DATABASES LIKE 'DBNAME'");

if(!$rs2) echo "\n\n".$sq."\n".mysql_error()."\n\n"; else
while ($data2 = mysql_fetch_row($rs2))
{
$db=$data2[0];
$db_cha=PMA_getDbCollation($db);
if ( $db!='mysql' /* &&( $db=='mydb_x' || $db=='mydb_y' ) */ ) // limit to database(s) - $db=='mydb_x' || $db=='mydb_y' || $db=='mydb_z'
if ( @substr($db_cha[0],0,4)!='utf8' ) // limit to charset
{
 mysql_select_db($db);
$rs = mysql_query("SHOW TABLES");
if(!$rs) echo "\n\n".$sq."\n".mysql_error()."\n\n"; else
while ($data = mysql_fetch_row($rs))
{
 $rs1 = mysql_query("show FULL columns from $data[0]");
 if(!$rs1) echo "\n\n".$sq."\n".mysql_error()."\n\n"; else
 while ($data1 = mysql_fetch_assoc($rs1))
 {
  if(in_array(array_shift(split("\\(",$data1['Type'],2)),array(
//'national char',
//'nchar',
//'national varchar',
//'nvarchar',
'char',
'varchar',
'tinytext',
'text',
'mediumtext',
'longtext',
'enum',
'set'
  )))
  {
   if(substr($data1['Collation'],0,4)!='utf8') // limit to charset
   {
    $sq="ALTER TABLE `$data[0]` CHANGE `".$data1['Field'].'` `'.$data1['Field'].'` '.$data1['Type'].' CHARACTER SET binary '.($data1['Default']==''?'':($data1['Default']=='NULL'?' DEFAULT NULL':' DEFAULT \''.mysql_escape_string($data1['Default']).'\'')).($data1['Null']=='YES'?' NULL ':' NOT NULL').';';
    if(!$printonly&&!mysql_query($sq)) echo "\n\n".$sq."\n".mysql_error()."\n\n";
    else
    {
     echo ($sq."\n") ;
     $sq="ALTER TABLE `$data[0]` CHANGE `".$data1['Field'].'` `'.$data1['Field'].'` '.$data1['Type']." CHARACTER SET $charset ".($collate==''?'':"COLLATE $collate").($data1['Default']==''?'':($data1['Default']=='NULL'?' DEFAULT NULL':' DEFAULT \''.mysql_escape_string($data1['Default']).'\'')).($data1['Null']=='YES'?' NULL ':' NOT NULL').($data1['Comment']==''?'':' COMMENT \''.mysql_escape_string($data1['Comment']).'\'').';';
     if(!$printonly&&!mysql_query($sq)) echo "\n\n".$sq."\n".mysql_error()."\n\n";
     else echo ($sq."\n") ;
    }
   }
  }
 }
 if($altertablecharset)
 {
  /*
  $sq='ALTER TABLE `'.$data[0]."` DEFAULT CHARACTER SET binary";
  echo ($sq."\n") ;
  if(!mysql_query($sq)) echo "\n\n".$sq."\n".mysql_error()."\n\n";
  */
  $sq='ALTER TABLE `'.$data[0]."` DEFAULT CHARACTER SET $charset ".($collate==''?'':"COLLATE $collate");
  echo ($sq.";\n") ;
    if(!$printonly)
  if(!mysql_query($sq)) echo "\n\n".$sq."\n".mysql_error()."\n\n";
 }
}
 if($alterdatabasecharser)
 {
  /*
  $sq='ALTER DATABASE `'.$data2[0]."` DEFAULT CHARACTER SET binary";
  echo ($sq."\n") ;
  if(!mysql_query($sq)) echo "\n\n".$sq."\n".mysql_error()."\n\n";
  */
  $sq='ALTER DATABASE `'.$data2[0]."` DEFAULT CHARACTER SET $charset ".($collate==''?'':"COLLATE $collate;");
  echo ($sq."\n") ;
    if(!$printonly)
  if(!mysql_query($sq)) echo "\n\n".$sq."\n".mysql_error()."\n\n";
 }
}
}
?>
</xmp>

Change: DBUSERNAME, DBPASSWORD, and DBNAME accordingly.

5) Go to your blog's dashboard. Then go to the "Regional" settings. Make sure your active languages are "UTF-8" by editing each active language/locale and changing the "Charset:" to "UTF-8".

You should be able to afterwards. See for example: http://laibcoms.asia/blog/xindao (the blog name is in Chinese)

* Note: crash instructions. I'll add it to my list of ToDo articles ^_^


Form is loading...