使用 PHP 的 SoapClient 将 UTF-16 字符发送到 WCF 服务

发布于 2024-07-19 17:55:00 字数 352 浏览 4 评论 0原文

我的 PHP 应用程序正在获取用户输入并将其发送到 WCF Web 服务。 有时,我的用户从 Word 复制并粘贴并将 UTF-16 字符获取到他们的消息中,例如“En Dash”\u2013

发生这种情况时,我会收到以下错误。

PHP 致命错误:SOAP-ERROR:编码: 字符串 '\xe2...' 无效 第 31 行 *** 中的 utf-8 字符串

我尝试将 SoapClient 构造函数的编码选项设置为“UTF-16”。 我的请求似乎有效,但我注意到 xml 标头上的编码仍然设置为 UTF-8。

有任何想法吗?

My PHP application is taking user input and sending it to a WCF Web Service.
Sometimes my users copy and paste from Word and get UTF-16 Characters into their message such as the "En Dash" \u2013

I get the following error when this occurs.

PHP Fatal error: SOAP-ERROR: Encoding:
string '\xe2...' is not a valid
utf-8 string in *** on line 31

I've tried setting the encoding option of the SoapClient constructor to 'UTF-16'.
My request seems to work, but I notice the encoding on the xml header is still set to UTF-8.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

反话 2024-07-26 17:55:00

WCF 仅适用于 UTF-8,而 word 默认适用于 UTF-16,这解释了为什么它看起来像 UTF8

尝试使用 mbstring 来纠正问题

WCF works in UTF-8 only and word works in UTF-16 by default which explains why its lookling like UTF8

Try using mbstring to correct the issue

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文