[英]PHP SOAP Client with Special Characters (Encoding)?
I'm trying a SOAP Client with PHP. 我正在尝试使用PHP的SOAP客户端。 It is ok as i simply know it. 这很好,因为我只是知道它。 But there is a problem when the Data contains Special Character
inside. 但是当Data contains Special Character
时会出现问题。

in the data.) (它来自Hex-code 
在数据中。) Following is the sample: 以下是样本:
header('Content-Type: text/plain; charset=UTF-8');
$client = new SoapClient('http://www.example.com/webservice.asmx?WSDL', array('trace' => 1, 'encoding'=>'UTF-8'));
$result_1 = $client->GetText();
$result_2 = $client->GetText_withSpecialCharacter(); //Data contains `` hex-code (♫ Special Character)
var_dump($result_1);
var_dump($result_2);
$result_1
properly 我总是正确得到$result_1
$result_2
(It always returns BLANK) 但是, 从来没有得到$result_2
(它总是返回BLANK) Please suggest me what should i do with it? 请建议我该怎么办?
You can try setting the encoding to UTF-8
您可以尝试将编码设置为UTF-8
Example 例
$client = new SoapClient('http://www.example.com/webservice.asmx?WSDL', array('trace' => 1, 'encoding'=>' UTF-8'));
try 尝试
$result_1 = urldecode($client->GetText());
$result_2 = urldecode($client->GetText_withSpecialCharacter());
Maybe you can try this : 也许你可以试试这个:
$myString = $client->GetText_withSpecialCharacter();
$result_2 = urldecode($myString);
if ($myString != urlencode($result_2)) {
$result_2 = mb_convert_encoding($myString, "UTF-8", mb_detect_encoding($myString,"auto",true));
}
The question is very old but there is a solution: 问题很老但有一个解决方案:
$result_2 = html_entity_decode($client->GetText_withSpecialCharacter(), ENT_QUOTES | ENT_XML1);
But 
但
does not seem to be a valid UTF-8 character. 似乎不是有效的UTF-8字符。 0xE
is Shift Out character. 0xE
是Shift Out字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.