开发者

PHP: convert all characters to HTML entities

How to convert all characters in a string to HTML entities?

html开发者_如何学编程entities() doesn't work for characters like ćĆČ芚ĐđŽž


<?php

function encode($string) {
    return mb_encode_numericentity($string, array(0x000000, 0x10ffff, 0, 0xffffff), 'UTF-8');
}

echo encode('ćĆČ芚ĐđŽž');

Result is &#263;&#262;&#268;&#269;&#352;&#353;&#272;&#273;&#381;&#382;


There are no (named) entities for those characters.

You can see the list here. If you want to convert to numerical entities, see this answer.


The character code of "ć", is 263, which as an HTML entity is &#263;, and so forth.


It's widely known that some characters are not encoded with htmlentities();.

If you look at the docs, there are some posts with character maps you can use with str_replace()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜