Reputation: 35900
htmlentities($this->name, null, "UTF-8");
Does not encode the star (★). How can I make it encode the star?
Update: â
doesn't render a star. Also, I'm using:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Upvotes: 1
Views: 357
Reputation: 29462
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 ★ Star
Upvotes: 2
Reputation: 59699
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 â
.
Upvotes: 2