|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-12-28 20:46 UTC] vtsuper1 at mail dot hongkong dot com
Description:
------------
I have try this code in
php 5.0.3 and 4.3
I'm using Chinese winXP and Chinese Office XP
apache 2
both version of php also have the same problem
When I use Chinese character in the string, the output of the word file will have some meaningless spaces after the words I expected(my expected string is ok, no problem). There are no problem if I using English. And this problem will not occurs in excel.
Reproduce code:
---------------
<?php
// starting word
$word = new COM("word.application") 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("?A?n??");
$word->Documents[1]->SaveAs("Useless test.doc");
//closing word
$word->Quit();
//free the object
$word = null;
?>
Expected result:
----------------
?A?n??
Actual result:
--------------
?A?n??____
(there are some spaces occurs, I use the underline to repersent the spaces)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 04:00:01 2025 UTC |
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.