Facebook 分享描述的编码问题
当有人分享我的博客中的内容时,我遇到编码问题。 (fantasyelf.com/blog) 整个网站也包含西里尔字母符号和帖子。例如,当我在 Facebook 的个人资料上点赞该帖子时,标题是正确的,但在描述中只有“ÐÐ⁄бÑе дÐ⁄Ñли!”。我尝试将所有 .php 文件转换为不带 BOM 的 UTF-8,但随后我在打开帖子时遇到了问题。所以我将content.php文件改回正常。问题仍然存在。
I have a problem with the encoding when someone shares something from my blog. (fantasyelf.com/blog) The entire site contains Cyrillic symbols and the posts too. For example when I like the post on my profile in Facebook, the title is correct, but in the description there is only ÐобÑе доÑли!. I tried to convert all of my .php's to UTF-8 without BOM, but then I had problems with opening posts. So I changed the content.php file back to normal. The problem still exists.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了类似的问题,我的 WordPress 博客正确渲染了所有 UTF-8 内容,但某些(不是全部)包含非 ASCII 字符的文章在 Facebook 中被搞乱了。
罪魁祸首是 Wordpress 中元描述标头的自动截断。元描述标头不是在字符边界处而是在字节边界处被截断,因此在页面源中显示无效字符(作为问号)。这肯定打扰了 Facebook Open Graph 抓取工具。
我最终找到了手动调整这些博文内容的快速修复方法,这样截断就不会发生在非 ASCII(多字节)字符上。
I had a similar problem, where my wordpress blog was rendering all UTF-8 content correctly, but certain (not all) articles with non-ASCII characters were messed up in Facebook.
The culprit was auto-truncation of the meta description header in Wordpress. The meta description header was truncated not at a character boundary, but at a byte boundary, hence displaying invalid characters (as question marks) in the page source. That must've disturbed the Facebook Open Graph scraper.
I ended up with the quick fix of adjusting the content of those blogposts manually, so that the truncation would not happen upon a non-ASCII (multibyte) character.
尝试使用 GNU/Linux 的重新编码,我解决了将我的 WordPress 主题的 header.php 文件重新编码为 UTF-8 的问题。您还可以在 GNU/Linux 下使用 file -i myfile.php 查看语言环境配置并查看文件的编码。
也了解 opengraph 协议:http://ogp.me/
Try using recode from GNU/Linux, i solved the problem recoding to UTF-8 the header.php file of my wordpress theme. You can see also the locales configuration and view the encode of the file using file -i myfile.php under GNU/Linux too.
Read about the opengraph protocol too: http://ogp.me/