|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-04-23 07:30 UTC] kaija_jan at hotmail dot com
Description:
------------
I wrote a COM object by using delphi 5.
It do some comparision in the delphi object like the following code.
====================================================
function Ttest.comparestr(const a, b: WideString; c,
d: OleVariant): OleVariant;
var
e : widestring;
r : olevariant;
begin
e := '中文';
r := '';
if a = b then
r := r + 'a=b<br>'
else
r := r + 'a<>b<br>';
if c = d then
r := r + 'c=d<br>'
else
r := r + 'c<>d<br>';
if a = c then
r := r + 'a=c<br>'
else
r := r + 'a<>c<br>';
if a = e then
r := r + 'a=e<br>'
else
r := r + 'a<>e<br>';
if c = e then
r := r + 'c=e<br>'
else
r := r + 'c<>e<br>';
result := r;
end;
====================================================
It always shows a<>e and c<>e(others equal) when I use PHP COM funcion, and do chinese comparision. But It prints all equal if I send pure english words or some numeral vairants.
And It shows all equal while I using asp to call the COM object, whatever I send chinese or english.
Reproduce code:
---------------
<?php
$a = $b = $c = $d = "中文"; //some chinese words
$comtest = new COM("comtest.test1");
echo $comtest->comparestr($a, $b, $c, $d);
unset($comtest);
?>
php outputs:
a=b
c=d
a=c
a<>e
c<>e
=================================
<%
a = "中文" 'some chinese words
b = a
c = a
d = a
set comtest = server.createobject("comtest.test1")
response.write comtest.comparestr(a, b, c, d)
set comtest = nothing
%>
asp outputs:
a=b
c=d
a=c
a=e
c=e
Expected result:
----------------
output:
a=b
c=d
a=c
a=e
c=e
Actual result:
--------------
output:
a=b
c=d
a=c
a<>e
c<>e
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 17:00:01 2025 UTC |
You need to tell COM that the text is chinese. There are two ways to achieve this: set com.code_page ini setting to the number corresponding to chinese (this is the default code_page used by PHP--the default is CP_ACP), or set the code_page in the third parameter of the COM constructor: $obj = new COM("comtest.test1", null, $codepage); PHP defines these constants for codepages; they can be used both in your scripts and in the php.ini: CP_ACP CP_MACCP CP_OEMCP CP_UTF7 CP_UTF8 CP_SYMBOL CP_THREAD_ACP You can use the numeric value for the chinese code page directly if you know it (you probably want 950 or 936). Consult MSDN for more information: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/act/htm/actml_ref_scpg.asp$obj = new COM("comtest.test1", null, 950); I got the same result after I modify the codepage parameter. ====================== a=b c=d a=c a<>e c<>e ====================== And I tried each codepage under. CP_ACP, CP_MACCP, CP_OEMCP, CP_UTF7, CP_UTF8, CP_SYMBOL, CP_THREAD_ACP I also tried the same code in PHP 4.3.6(It crashes php in 4.3.4), It gives me the same result as PHP 5 RC1.Could you please adjust your COM object to return e instead, and paste the output of this script here? <?php $a = $b = $c = $d = "中文"; //some chinese words $comtest = new COM("comtest.test1"); $e = $comtest->comparestr($a, $b, $c, $d); echo "d is " . bin2hex($d) . "\n"; echo "e is " . bin2hex($e) . "\n"; ?>