PHP html 解码帮助 - 转换:A 'quote' <b>粗体</b>

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3574609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:16:45  来源:igfitidea点击:

PHP html decoding help - converting: A &#039;quote&#039; is <b>bold</b>

phphtml-encode

提问by tzmatt7447

I need to convert a string like this:

我需要转换这样的字符串:

A &#039;quote&#039; is <b>bold</b>

into:

进入:

A 'quote' is <b>bold</b>

html_entity_decode()did not work.

html_entity_decode()不工作。

回答by Robert Ros

Make sure you use the right quote_style:

确保使用正确的 quote_style:

html_entity_decode('A &#039;quote&#039; is <b>bold</b>', ENT_QUOTES);

html_entity_decode('A &#039;quote&#039; is <b>bold</b>', ENT_QUOTES);

ENT_QUOTES Will convert both double and single quotes. (PHP Manual: html_entity_decode)

ENT_QUOTES 将转换双引号和单引号。( PHP 手册: html_entity_decode)

回答by Artefacto

mb_convert_encoding($string, "UTF-8", "HTML-ENTITIES");

You can replace "UTF-8" with whatever encoding you need (though depending on the encoding you choose, certain characters may not be representable).

您可以用您需要的任何编码替换“UTF-8”(尽管根据您选择的编码,某些字符可能无法表示)。