【发布时间】:2016-05-12 10:10:24
【问题描述】:
我有以下字符串:
$string = "★ This is some text ★";
我想把它转换成html实体:
$string = "★ This is some text ★";
大家都在写的解决方案:
htmlentities("★ This is some text ★", "UTF-8");
但 htmlentities 无法将所有 unicode 转换为 html 实体。所以它只是给我与输入相同的输出:
★ This is some text ★
我也尝试将此解决方案与两者结合起来:
header('Content-Type: text/plain; charset=utf-8');
和:
mb_convert_encoding();
但这要么打印结果为空,要么根本不转换,要么错误地将星星转换为:
Â
如何将 ★ 和所有其他 unicode 字符转换为正确的 html 实体?
【问题讨论】:
标签: php unicode utf-8 html-entities