我这边测试通过啊.....
结果:
&nbsp;<"测试">&nbsp;&lt;&quot;测试&quot;&gt;
程序:
<? 
$s = '&nbsp;<"测试">';
echo $s;
echo "\n\n";
$s = htmlspecialchars_uni($s, false);
echo $s;
function htmlspecialchars_uni($text, $entities = true)
{ return str_replace(
// replace special html characters
array('<', '>', '"'),
array('&lt;', '&gt;', '&quot;'),
preg_replace(
// translates all non-unicode entities
'/&(?!' . ($entities ? '#[0-9]+' : '(#[0-9]+|[a-z]+)') . ';)/si',
'&amp;',
$text
)
);
}
?>