CJK 空白字符消失
我有一个 PHP 脚本,它通过 Salesforce API 从 Salesforce 获取数据,并使用 file_put_contents 将输出写入文件。该数据是韩文字符和英文字符的混合。
当我在运行带有 PHP 5.2.8 的 Red Hat Enterprise Linux ES 版本 4(Nahant Update 8)的盒子 (1) 和运行 PHP 5.3.6 的类似盒子 (2) 上运行脚本时,韩文字符之间的空格消失了。
例如(使用 K 代表韩文字符,E 代表英文字符)
EEEEEEEEK KKK KKKK EEE KKKK 显示为 EEEEEEEEKKKKKKKK EEE KKKK
但是,当我在运行 CentOs 且 PHP 5.3.5 或 ( 4) 我的本地 Windows 机器使用 PHP 5.3.6 文件中的文本是正确的。
谁能建议问题可能是什么?
编辑 - 最初我是通过浏览器访问 php 脚本,但是为了(希望)简化问题,我当前将输出存储在文本文件中并将其下载到我的 Windows 计算机。
编辑 - 十六进制版本
原始文本 - CFD란 무엇입니까?
十六进制 (1) - 43 46 44 eb 9e 80 eb ac b4 ec 97 87 ec 9e 85 eb 8b 88 ea b9 8c 3f 十六进制
(3) - 43 46 44 eb 9e 80 20 eb ac b4 ec 97 87 ec 9e 85 EB 8b 88 ea b9 8c 3f
EDIT - 用于选择文本的代码(省略用户、通行证、表、ID 和路径)
<?php
ini_set("soap.wsdl_cache_enabled", "0");
require_once ("../soapclient/SforcePartnerClient.php");
require_once ("../soapclient/SforceHeaderOptions.php");
$partner_wsdl = "../soapclient/new-partner.wsdl.xml";
$client = new SforcePartnerClient();
$client->createConnection($partner_wsdl);
$loginResult = $client->login('--user--', '--pass--');
$query = "Select Name FROM --table-- WHERE Id = '--id--'";
$response = $client->query($query);
echo'<pre>';print_r($response);echo'</pre>';
$queryResult = new QueryResult($response);
foreach ($queryResult->records as $qr) {
$content = $qr->fields->Name;
file_put_contents('--path--',$content);
}
?>
I have a PHP script which fetches data from Salesforce via the Salesforce API and writes the output to a file using file_put_contents. The data is a mixture of Korean characters and English characters.
When I run the script on a box (1) running Red Hat Enterprise Linux ES release 4 (Nahant Update 8) with PHP 5.2.8 and a similar box (2) running PHP 5.3.6 the spaces in between the Korean characters disappear.
e.g. (Using K to represent a Korean character and E to represent an English character)
EEEEEEEEK KKK KKKK EEE KKKK is appearing as EEEEEEEEKKKKKKKK EEE KKKK
However when I run the script on a box (3) running CentOs with PHP 5.3.5 or on (4) my local windows machine with PHP 5.3.6 the text in the file is correct.
Can anyone suggest what the problem might be?
EDIT - Originally I was accessing the php script via a browser however to (hopefully) simplify the problem I am currently storing the output in a text file and downloading it to my windows machine.
EDIT - Hex version
Original text - CFD란 무엇입니까?
Hex from (1) - 43 46 44 eb 9e 80 eb ac b4 ec 97 87 ec 9e 85 eb 8b 88 ea b9 8c 3f
Hex from (3) - 43 46 44 eb 9e 80 20 eb ac b4 ec 97 87 ec 9e 85 eb 8b 88 ea b9 8c 3f
EDIT - Code used to select text (with user, pass, table, id and path omitted)
<?php
ini_set("soap.wsdl_cache_enabled", "0");
require_once ("../soapclient/SforcePartnerClient.php");
require_once ("../soapclient/SforceHeaderOptions.php");
$partner_wsdl = "../soapclient/new-partner.wsdl.xml";
$client = new SforcePartnerClient();
$client->createConnection($partner_wsdl);
$loginResult = $client->login('--user--', '--pass--');
$query = "Select Name FROM --table-- WHERE Id = '--id--'";
$response = $client->query($query);
echo'<pre>';print_r($response);echo'</pre>';
$queryResult = new QueryResult($response);
foreach ($queryResult->records as $qr) {
$content = $qr->fields->Name;
file_put_contents('--path--',$content);
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过更多研究,我发现 SforcePartnerClient.php 中的一个函数
根据所使用的框返回不同的值。
框 1 和 2:
框 3 和 4:
当使用 XML 解析器(文件后面)和 WSDL 文件将其与/解析/转换时,XML 解析器会去除连续的 &#xxxxx; 之间出现的任何空格。 s - 我相信这与错误 https://bugs.php.net/bug 有关.php?id=33240 为了避免这种情况,我建议注释掉 SforcePartnerClient.php 的第 364 行。
不幸的是,我不知道这是否会对使用 SforcePartnerClient.php 的其他代码产生任何不利影响。
After more research I discovered a function in the SforcePartnerClient.php
is returning different values depending on the box used.
Box 1 and 2:
Box 3 and 4:
When this is combined with / parsed / converted using the XML parser (later in the file) and WSDL file the XML parser strips any white space that occurs between consecutive &#xxxxx; s - I believe this is related to a bug https://bugs.php.net/bug.php?id=33240 to avoid this I suggest commenting out line 364 of SforcePartnerClient.php
Unfortunately I do not know if this will have any adverse effects on other code using SforcePartnerClient.php.