如何在 PHP 中从 api Facebook 转换为 ISO-8859-1 数据?
我需要将从 api Facebook 检索到的数据转换为 php 中的 ISO-8859-1。
这是 facebook api 的输出示例(查看描述值) 我看 php api facebook 使用了这个方法
protected static function base64UrlDecode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
{
"id": "108012702561007",
"name": "Sud Sound System",
"link": "http://www.facebook.com/pages/Sud-Sound-System/108012702561007",
"likes": 24904,
"category": "Musician/band",
"website": "http://www.sudsoundsystem.eu",
"is_community_page": true,
"description": "\u003cp>I \u003cb>Sud Sound System\u003c/b>",
"parking": {
"street": 0,
"lot": 0,
"valet": 0
},
}
I need to convert the data retrived from api Facebook to ISO-8859-1 in php.
This is an example of output of the api facebook (look to description value)
I look that the php api facebook used this method
protected static function base64UrlDecode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
{
"id": "108012702561007",
"name": "Sud Sound System",
"link": "http://www.facebook.com/pages/Sud-Sound-System/108012702561007",
"likes": 24904,
"category": "Musician/band",
"website": "http://www.sudsoundsystem.eu",
"is_community_page": true,
"description": "\u003cp>I \u003cb>Sud Sound System\u003c/b>",
"parking": {
"street": 0,
"lot": 0,
"valet": 0
},
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSON 定义该转义语法作为 Unicode UTF-8 编码的替代方案。
这里建议了一个解决方案: 如何将“\u00ed”等 Unicode 转义序列解码为正确的 UTF-8 编码字符?
有关 UTF-8 转义格式的说明可以在此处找到:JSON 字符编码 - 浏览器很好地支持 UTF-8 还是应该使用数字转义序列? (哪一点到 RFC:http://www.ietf.org/rfc/rfc4627.txt)。
就您而言,您需要随后从 UTF-8 转换为 ISO-8859-1(尽管恕我直言,您最好一直使用 UTF-8)。
JSON defines that escaping syntax as an alternative to Unicode UTF-8 encoding.
A solution was suggested here: How to decode Unicode escape sequences like "\u00ed" to proper UTF-8 encoded characters?
An explanation about that UTF-8 escaping format can be found here: JSON character encoding - is UTF-8 well-supported by browsers or should I use numeric escape sequences? (which points to the RFC: http://www.ietf.org/rfc/rfc4627.txt).
In your case, you'll need to transform from UTF-8 to ISO-8859-1 afterwards (though imho you'd be better off using UTF-8 all along).