htmlentities($this->name, null, "UTF-8");
不编码星号 (★)。我怎样才能让它对星星进行编码?
更新: â
不渲染星星。另外,我正在使用:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
htmlentities($this->name, null, "UTF-8");
不编码星号 (★)。我怎样才能让它对星星进行编码?
更新: â
不渲染星星。另外,我正在使用:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
在 PHP >= 5.4 中,参数的默认值encoding
更改为UTF-8
.
如果您使用:
htmlentities( "★", null, "ISO-8859-1");
星号将转换为â
.
我怎样才能让它对星星进行编码?
你不能。htmlentities
不编码所有 Unicode 字符。但是你可以尝试一些解决方法,比如这个
或者您可以使用以下输出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