简体   繁体   中英

PHP SOAP Client with Special Characters (Encoding)?

I'm trying a SOAP Client with PHP. It is ok as i simply know it. But there is a problem when the Data contains Special Character inside.

  • Special Character like inside. (It comes as Hex-code  in the data.)

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);
  • I always got $result_1 properly
  • But, NEVER got $result_2 (It always returns BLANK)

Please suggest me what should i do with it?

You can try setting the encoding to 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. 0xE is Shift Out character.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM