1
htmlentities($this->name, null, "UTF-8");

Does not encode the star (★). How can I make it encode the star?

Update: &acirc doesn't render a star. Also, I'm using:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

2 Answers 2

2

In PHP >= 5.4, the default value of the encoding parameter was changed to UTF-8.

If you use:

htmlentities( "★", null, "ISO-8859-1");

The star character will be converted to &acirc;.

2
2

How can I make it encode the star?

You can't. htmlentities does not encode all Unicode characters. But you can try some workarounds, like this one

Or you can make use of output from json_encode:

$txt = preg_replace_callback(
    '/[\x80-\xFF]{3,}/', //do not trust this, it's only example that works for small range of unicode characters, that happens to include black star 
     function($m){ 
         return str_replace('\\u','&#x',trim(json_encode($m[0]),'"')).';';
      }, "Black ★ Star"
); // Black &#x2605; Star

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.