SOAP-ERROR: Encoding: string ... is not a valid utf-8 string

Hi, I have a web service created using the Zend Framework. One of the methods is designed to send order information. I ran into an encoding problem. One of the return values ​​contains the following:

Jaime Torres Bode # 322-Colonel Lomas de Santa Maria

The web service returns the following error:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Body>
      <SOAP-ENV:Fault>
         <faultcode>SOAP-ENV:Server</faultcode>
         <faultstring>SOAP-ERROR: Encoding: string 'Jaime Torres Bodet #322-A Col. Lomas de Santa Mar\xc3...' is not a valid utf-8 string</faultstring>
      </SOAP-ENV:Fault>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

How do I solve this problem?

Thanks


Continued: The problem is with a truncated row in the database. The field was set to VARCHAR (50), and it was truncated exactly in the middle of the encoded value.

+6
source share
6 answers

- , :

$request->Text = substr($text, 0, 40);

substr mb_substr, , :

$request->Test = mb_substr($text, 0, 40, 'utf8');
+9

:

SERVER:

$server = new SoapServer("some.wsdl", array('encoding'=>'ISO-8859-1')); // for 'windows-1252' too

:

$server = new SoapClient("some.wsdl", array('encoding'=>'ISO-8859-1')); // for 'windows-1252' too

... UTF-8, , ,

+16

, í!= i. UTF-8 . :

$string = iconv('windows-1252', 'UTF-8', $string);

. http://php.net/iconv

+4

, , :

// encode in UTF-8
$string = utf8_encode($string);

.

: utf8_encode()

+4

​​, mb_convert_encoding array_walk_recursive, POST $params (array).

, :

array_walk_recursive($params,function (&$item){
    $item = mb_convert_encoding($item, 'UTF-8');
});
0

, , UTF-8. UTF-8 .

, UTF-8, // Å

0

All Articles