如何在PHP字符串中删除%EF%BB%BF [英] How to remove %EF%BB%BF in a PHP string

查看:534
本文介绍了如何在PHP字符串中删除%EF%BB%BF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Microsoft Bing API.

I am trying to use the Microsoft Bing API.

$data = file_get_contents("http://api.microsofttranslator.com/V2/Ajax.svc/Speak?appId=APPID&text={$text}&language=ja&format=audio/wav");
$data = stripslashes(trim($data));

返回的数据在返回的字符串的第一个字符中带有一个''字符.它不是空格,因为我在返回数据之前对其进行了修剪.

The data returned has a ' ' character in the first character of the returned string. It is not a space, because I trimed it before returning the data.

"字符原来是%EF%BB%BF.

The ' ' character turned out to be %EF%BB%BF.

我想知道为什么会发生这种情况,也许是Microsoft的错误?

I wonder why this happened, maybe a bug from Microsoft?

如何在PHP中删除此%EF%BB%BF?

How can I remove this %EF%BB%BF in PHP?

推荐答案

您可以仅将 substr 剩下的不用 UTF-8 BOM :

// if it’s binary UTF-8
$data = substr($data, 3);
// if it’s percent-encoded UTF-8
$data = substr($data, 9);

这篇关于如何在PHP字符串中删除%EF%BB%BF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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