元描述编码 - 以问号形式返回的引号 PHP
当我从此网站的元描述标签检索引号时: http://mashable .com/2011/04/14/google-computers-regret/
“regret”一词周围的引号返回为问号。
我正在使用以下代码,而 $str 是返回的元数据:
if(mb_detect_encoding($str, 'UTF-8, ISO-8859-1', true) != 'ISO-8859-1') $str = utf8_decode($str);
$str = strtr($str, get_html_translation_table(HTML_ENTITIES));
$str = strip_tags(html_entity_decode(htmlspecialchars_decode($str, ENT_NOQUOTES), ENT_NOQUOTES, "UTF-8"));
$str = html_entity_decode($str, ENT_QUOTES,"UTF-8");
我该如何解决这个问题?
When I retrieve quotes from the meta description tag of this site: http://mashable.com/2011/04/14/google-computers-regret/
The quotes around the word "regret" return as question marks.
I am using the following code whereas $str is the meta data returned:
if(mb_detect_encoding($str, 'UTF-8, ISO-8859-1', true) != 'ISO-8859-1') $str = utf8_decode($str);
$str = strtr($str, get_html_translation_table(HTML_ENTITIES));
$str = strip_tags(html_entity_decode(htmlspecialchars_decode($str, ENT_NOQUOTES), ENT_NOQUOTES, "UTF-8"));
$str = html_entity_decode($str, ENT_QUOTES,"UTF-8");
How can I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将生成的 HTML 输出为 UTF-8。
Output your resulting HTML as UTF-8.
这是一个原始的修复,我确信有更好的方法,但是:
这应该用简单的引号替换这些风格化的引号,并防止问号问题。
(很高兴学习比这个笨重的解决方案更好、更智能的解决方案。)
根据下面的评论进行修改:
您可以使用此函数用相同的替换 str 替换多个模式(保存在数组中) - 比必须填充一个更好具有相同内容的数组,或者在不需要时创建一个笨重的函数。
It's a primitive fix, and I am sure there is a better way of doing it, but:
That should replace these stylised quotation marks with a simple quotation mark and prevent the question mark issue.
(Happy to learn any better, more intelligent, solutions than this clunky one.)
Revised based on comment below:
You can replace multiple patterns (held in an array) with the same replacement str using this function - better than having to pad out an array with the same content, or create a clunky function when it is not needed.