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

不编码星号 (★)。我怎样才能让它对星星进行编码?

更新: &acirc不渲染星星。另外,我正在使用:

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

4

2 回答 2

2

在 PHP >= 5.4 中,参数的默认值encoding更改为UTF-8.

如果您使用:

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

星号将转换为&acirc;.

于 2012-12-18T21:29:36.427 回答
2

我怎样才能让它对星星进行编码?

你不能。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 &#x2605; Star
于 2012-12-18T22:24:30.870 回答