'PHP: convert all UTF-8 characters to HTML entities

I am attempting to use mb_encode_numericentity() to convert all special UTF-8 characters into HTML entities. The following code converts some characters, like ㋡, but not others, like 𝑥.

echo encodespecial('㋡ ヅ Hello World 𝑥 𝑦 𝑧');

function encodespecial($str)
{
    $convmap = array(0x80, 0xffff, 0, 0xffff);
    
    return mb_encode_numericentity($str, $convmap, 'UTF-8');
}


Solution 1:[1]

Here is the solution, based on CBroe's explanation:

echo encodespecial('? ? Hello World ? ? ? this is a test....');
function encodespecial($str) {
    $convmap = array(0x80, 0xfffffff, 0, 0xfffffff);
    return mb_encode_numericentity($str, $convmap, 'UTF-8');
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 micvelodia