5

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?

夏期劇場
  • 17,821
  • 44
  • 135
  • 217

4 Answers4

1

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'));
Baba
  • 94,024
  • 28
  • 166
  • 217
0

try

 $result_1 = urldecode($client->GetText());
 $result_2 = urldecode($client->GetText_withSpecialCharacter()); 
Teena Thomas
  • 5,139
  • 1
  • 13
  • 17
  • Still not working. It even returns `NULL` for already working `$result_1`. Whenever i put `urldecode`, `htmlspecialchars_decode`, `htmlentities`, etc to wrap the soap function call there, it always returns `NULL` :( – 夏期劇場 Sep 23 '12 at 14:48
0

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));
}
0

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.