php - 将 unicode 字符转换为 html 特殊字符
问题描述
我将 unicode 字符嵌入到这样的字符串中:
64\u00be w × 19\u00bd d × 16\u00be h in (164 × 50 × 43 cm)
现在我想像这样转换它们:
64¾ w × 19½ d × 16¾ h in 164 × 50 × 43 cm
到目前为止,我试过这个:
$desc = '64\u00be w × 19\u00bd d × 16\u00be h in (164 × 50 × 43 cm)';
echo mb_convert_encoding($desc, 'ASCII', 'HTML-ENTITIES')
echo html_entity_decode( mb_convert_encoding ( $desc, 'HTML-ENTITIES', 'ASCII' )
但是两者都不会转换 unicode 字符,我在这里缺少什么?
解决方案
您可以使用这样的简单 hack(它不应该有任何性能问题):
$a = '64\u00be w × 19\u00bd d × 16\u00be h in (164 × 50 × 43 cm)';
$html = json_decode('"' . $a . '"');
echo $html;
推荐阅读
- arrays - Python 3.73 插入到 bytearray =“对象不能重新调整大小”
- python - wxPython手动滚动面板ScrolledPanel失败,wx.Grid
- python - 在字典中的列表中查找值
- sql - 如何添加限制条件,根据您的出生日期,您只能借一定数量的书籍?
- uitableview - 如何在单元格之间的 UITABLEVIEW 中添加间距?
- node.js - mongodb mongoose中的重复键错误索引
- php - 在 WooCommerce 购物车上定位特定产品 ID 显示数量
- r - R Shiny - 我的观察函数({UpdateSelectInput})有什么问题?
- sql - SQL WHERE IN,每个 IN id 的结果有限且已排序
- ruby-on-rails - Rails Sitemap_generator 使用 aws_fog 配置