[英]Convert unicode characters to html special characters
我將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字符,我在這里缺少什么?
您可以使用像這樣的簡單技巧(它應該沒有任何性能問題):
$a = '64\u00be w × 19\u00bd d × 16\u00be h in (164 × 50 × 43 cm)';
$html = json_decode('"' . $a . '"');
echo $html;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.