Login   Register  
PHP Classes
elePHPant
Icontem

Can't get it to work

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Chinese Party  >  All threads  >  Can't get it to work  >  (Un) Subscribe thread alerts  
Subject:Can't get it to work
Summary:Can't get it to work
Messages:5
Author:Timothy
Date:2007-05-17 14:30:47
Update:2011-10-21 06:02:36
 

  1. Can't get it to work   Reply  
Picture of Timothy
Timothy
2007-05-17 14:30:47
I am encountering some problem with a sample. I am hoping that someone can help me out.

The following is a sample code. I work in utf-8 format. I just can't get it to work. I get garbage output. What do I do wrong?

<?php
require('chinese_party.class.php');
$cconv =& new chinese_party();
$strContent = '&#32321;&#31777;&#36681;&#25563;&#28204;&#35430;';
$strContent = $cconv->u82tchi($strContent);
$charset = 'big5';
?>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=<?=$charset?>"></head>
<body><?=$strContent?></body>
</html>

I was able to get the sample to work and my email converted to big5 with the other class. But you need to email the author for a folder of binary files.

http://www.phpclasses.org/browse/package/3678.html

  2. Re: Can't get it to work   Reply  
Picture of Mickey Chan
Mickey Chan
2007-05-18 04:31:58 - In reply to message 1 from Timothy
Thank you for using chineseParty.

The original design of chineseParty is to handle Chinese characters directly but not its 'code'. Therefore I have not implemented unicode checking and conversion during convert utf-8 encoded characters to other encode.

There is a helper method 'chineseParty::ascii_decode()' can help you to handle this matter. If you are always handling contents that mixed up with character and 'codes' (which should rarely happened if your system is pure UTF-8), you better do this checking before any conversion. Below please found the modified code based on your sample. I will check if it is good to do ascii_decode transparently inside all utf8 conversion method.

Another possible reason why the converted characters become garbage may come from the default_charset setting of PHP. If your PHP is setup for any charset other then big5, it is not possible for changing the display charset by using META TAG. You should send a 'Content-Type' header to tell the client browser what charset you are using, like the sample below. This won't happen on email.

Please be reminded that the character conversion should always do right before you display it or send it out.

Regards,
Mickey

==========
<?php
require('chinese_party.class.php');
$cconv =& new chinese_party();
$strContent = '&#32321;&#31777;&#36681;&#25563;&#28204;&#35430;';
$strContent = $cconv->ascii_decode($strContent); // Add by Mickey
$strContent = $cconv->u82tchi($strContent);
$charset = 'big5';
header ('Content-Type: text/html; charset='.$charset); // send header because my server is restricted for UTF-8
?>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=<?=$charset?>"></head>
<body>
<?=$strContent?>
</body>
</html>

  3. Re: Can't get it to work   Reply  
Picture of Timothy
Timothy
2007-05-18 13:02:14 - In reply to message 2 from Mickey Chan
I am sorry. The original message didn't display the $strContent assigment properly.

$strContent = '&#32321;&#31777;&#36681;&#25563;&#28204;&#35430;';

should contain Chinese characters instead of the "codes" and the file is saved in utf-8. I have sent you an email with the php file attached. I will resend the email again.

Actually, I was wrong, there is no garbage in the output. The output is blank. The code fails when $sbit > 223 && $sbit < 240. Just copy the code and replace the "codes" above with any chinese characters. Save the file in utf-8 format. When executed, the resulting html should display the exact same thing but in big5 format. But I get a blank page.

  4. Re: Can't get it to work   Reply  
Picture of Mickey Chan
Mickey Chan
2007-05-19 04:30:27 - In reply to message 3 from Timothy
Hi,

I am tried your code again any found any problem. The line you have mentioned should not make any problem. ord() and substr() are very common functions. You may print the $sbit out to see what value is it. Did any error message shown? Please use `ini_set("display_errors", "1");error_reporting(E_ALL);` to capture any possible error message.

Have you checked that you server have installed mbstring and iconv extension? chineseParty need them.

Regards,
Mickey

  5. Re: Can't get it to work   Reply  
Picture of Peter Pan
Peter Pan
2011-10-21 06:02:36 - In reply to message 1 from Timothy
Dear Chinese Party Author,

First of all, thank you very much for sharing this tool, which I've been looking for a long long time.
I downloaded and tried your code, but it does not make any conversion, unfortunately. I am converting traditional to simplified chinese. It always shows traditional on the page.

Here's the code made from your "index.php". It's quite straight forward.

=======
<?php
/**
* Traditional Chinese <-> Simplified Chinese Example
* 2006-05-23 20:57
*/

require('chinese_party.class.php');

$cconv =& new chinese_party();

$strContent = $cconv->utf8_tchi2schi("&#23433;&#24944;&#24962;&#20663;&#30772;&#30862;&#30340;&#38728;");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>&#32321;&#31777;&#36681;&#25563;&#28204;&#35430;</title>
</head>
<body>
<h3>&#32321; => &#31777;&#36681;&#25563;&#32080;&#26524;</h3>
<?=$strContent?><br />
<hr />
<p><b>&#24050;&#30693;&#22312;Big5&#23383;&#30908;&#35041;&#28961;&#27861;&#27491;&#24120;&#36681;&#25563;&#28858;GB2312&#30340;&#20013;&#25991;&#23383;&#65306;</b><br />&#21633;(<?=$cconv->uniord('&#21633;');?>);&#25653;(<?=$cconv->uniord('&#25653;');?>);&#20871;(<?=$cconv->uniord('&#20871;');?>);&#30945;(<?=$cconv->uniord('&#30945;');?>);&#36619;(<?=$cconv->uniord('&#36619;');?>);</p>
</body>
</html>