How to convert all characters in a string to HTML entities?
htmlentities() 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.
preg_replace_callback and the regex "/[^\x00-\x7F]/".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()