Bug #31327 [Com]: chinese char and word problem
| From: | katszym at gmail dot com | Date: | Wed, 18 Feb 2015 00:31:40 +0000 |
| Subject: | Bug #31327 [Com]: chinese char and word problem | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-190760@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=31327&edit=1
ID: 31327
Comment by: katszym at gmail dot com
Reported by: vtsuper1 at mail dot hongkong dot com
Summary: chinese char and word problem
Status: Open
Type: Bug
Package: COM related
Operating System: win32
PHP Version: 5CVS-2005-08-30
Block user comment: N
Private report: N
New Comment:
I think I'm experiencing the same problem, but I'm not sure because I can't see the
original problem text on this page.
I have documented my problem on StackOverflow with simple code to reproduce: http://stackoverflow.com/questions/28534219/writing-utf-8-strings-to-word-using-php-com
Environment: I'm using Windows 7 Enterprise, Apache, MySQL, PHP 5.2.17, and Microsoft Office
2010.
It seems like the string length is not calculated correctly (using bytes and not characters),
resulting in a longer string with garbage at the end.
Previous Comments:
------------------------------------------------------------------------
[2007-06-15 07:41:12] tonyhook dot su at gmail dot com
When I upgraded PHP to 5.2.0, this problem still exists.
Several "encoding-traslate" codes don't make effect.
Windows Server 2003 R2 SP2
Apache 2
Office 2003 SP2
------------------------------------------------------------------------
[2005-09-08 06:05:50] vtsuper1 at mail dot hongkong dot com
I have see the lastest version of php 5.0.5 and 5.1
but the change log haven't mention about this bug has been fixed. So would you tell me the
developer doesn't think that this is a bug so they will not fix it or they are try to fixing it
but didn't finish yet?
------------------------------------------------------------------------
[2005-08-16 04:53:35] vtsuper1 at mail dot hongkong dot com
After yours information, I have try to modified my code and make it support the correct code_page.
But finially the result is exactly the same with my first script. There are some meaningless square
appears after my Chinese word. (Actually I'm quite confused that why only Word has this problem
but excel didn't?)
here are some link related to this problem:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/act/htm/actml_ref_scpg.asp
http://bugs.php.net/bug.php?id=31327
http://bugs.php.net/bug.php?id=28117
http://hk.php.net/manual/en/class.com.php
here are my new scripts:
<?php
$code_page=array('950','0','1','2','3','65001');
for ($i=0;$i<count($code_page);$i++){
// starting word
$word = new COM("word.application",NULL,$code_page[$i]) or die("Unable to
instantiate Word");
echo "Loaded Word, version {$word->Version}\n";
//bring it to front
$word->Visible = 1;
//open an empty document
$word->Documents->Add();
//do some weird stuff
$word->Selection->TypeText("ÄãºÃá");
$word->Documents[1]->SaveAs("D:\AppServ\www\word\\".$code_page[$i].".doc");
//closing word
$word->Quit();
//free the object
$word = null;
}
?>
------------------------------------------------------------------------
[2005-08-11 16:11:55] wez@php.net
Make sure you're setting up the code page properly.
From the manual:
com.code_page
It controls the default character set code-page to use when passing strings to and from COM
objects. If set to an empty string, PHP will assume that you want CP_ACP, which is the default
system ANSI code page.
If the text in your scripts is encoded using a different encoding/character set by default,
setting this directive will save you from having to pass the code page as a parameter to the COM
class constructor. Please note that by using this directive (as with any PHP configuration
directive), your PHP script becomes less portable; you should use the COM constructor parameter
whenever possible.
Consult MSDN for more information on code pages.
------------------------------------------------------------------------
[2005-08-08 11:21:52] bmcrowley at lcwarriormail dot com
I am experiencing the same bug with Arabic - I pull a UTF-8 character from a database, and push it
into Word with UTF-8 for the characterset. I get meaningless characters (the box) appearing after
(to the right of) the arabic text. Also, the arabic text gets mangled - words out of order...
I would try to post the input/output here, but it would be meaningless...
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=31327
--
Edit this bug report at https://bugs.php.net/bug.php?id=31327&edit=1