SOAP-ERROR: Encoding: string ... 不是有效的 utf-8 字符串 [英] SOAP-ERROR: Encoding: string ... is not a valid utf-8 string

查看:32
本文介绍了SOAP-ERROR: Encoding: string ... 不是有效的 utf-8 字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Zend 框架构建的 Web 服务.其中一种方法旨在发送有关订单的详细信息.我遇到了一些编码问题.返回的值之一包含以下内容:

Hi I have a web service built using the Zend Framework. One of the methods is intended to send details about an order. I ran into some encoding issue. One of the values being returned contains the following:

Jaime Torres Bodet #322-A Col. Lomas de Santa María

Web 服务返回以下错误:

The webservice is returning the following fault:

<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 Marxc3...' is not a valid utf-8 string</faultstring>
      </SOAP-ENV:Fault>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我应该如何解决这个问题?

How should I go about this problem?

谢谢

后续:问题是由数据库截断的字符串引起的.该字段被设置为 VARCHAR(50) 并且它正好在编码值的中间被截断.

Followup: Problem was due to a truncated string by the database. The field was set to VARCHAR(50) and it truncated exactly in the middle of the encoded value.

推荐答案

今天我遇到了同样的问题 - 导致该问题的代码是:

Today I run into same problem - the code which caused that problem was:

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

将 substr 更改为 mb_substr 似乎可以解决问题:

changing substr to mb_substr seems to solve the issue:

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

这篇关于SOAP-ERROR: Encoding: string ... 不是有效的 utf-8 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆