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 ćĆČ芚ĐđŽž
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 ć
, 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()
精彩评论