php-htmlspecialchars与unicode $string=“Główny folder grafik
asd nc”; echo htmlspecialchars($string); 现场php-htmlspecialchars与unicode $string=“Główny folder grafik,php,Php,asd nc”; echo htmlspecialchars($string); 现场 $string = "Główny folder grafik<p>asd nc</p>"; echo htmlspecialchars($string); Gł;ówny folder grafikasd nc 论地方 Główny folder grafik<p>asd nc</p> Głwny文件夹grafika
$string = "Główny folder grafik<p>asd nc</p>";
echo htmlspecialchars($string);
Gł;ówny folder grafikasd nc
论地方
Główny folder grafik<p>asd nc</p>
Głwny文件夹grafikasd nc
问题是什么?我希望当在实时站点上运行时,结果看起来像local接受其他参数——第三个是字符集
尝试指定第三个参数。您可能希望将一个可选参数传递给about charset,默认情况下该参数为ISO-8859-1。您需要向htmlspecialchars()函数添加额外的参数。以下方面应起作用:
Główny folder grafik<p>asd nc</p>
如果需要翻译所有具有关联命名实体的字符串,请改用
htmlspecialchars()
,该函数在所有方面都与htmlspecialchars()
相同,但与htmlspecialties()
不同,所有具有HTML字符实体等价物的字符都将转换为这些实体
但即使是htmlentities()
也不会对所有unicode字符进行编码。它编码它能编码的东西[所有的拉丁语1],而其他的则可以通过(例如,`Љ)
此函数用于查询ansii表以自定义包含/忽略您想要/不想要的字符
(注意:当然没有那么快)
/**
*Unicode证明htmlentities。
*将“普通”字符作为字符返回,将古怪字符作为数字html实体返回。
*@param string$str输入字符串
*@返回字符串编码输出
*/
功能超实体($str){
//除去现有实体,否则将重复转义
$str=html_entity_decode(斜杠($str),ENT_引号,'UTF-8');
$ar=preg_split('/(?为什么首先需要这样做?应该没有必要。
htmlspecialchars($string, ENT_QUOTES, "UTF-8");
/**
* Unicode-proof htmlentities.
* Returns 'normal' chars as chars and weirdos as numeric html entites.
* @param string $str input string
* @return string encoded output
*/
function superentities( $str ){
// get rid of existing entities else double-escape
$str = html_entity_decode(stripslashes($str),ENT_QUOTES,'UTF-8');
$ar = preg_split('/(?<!^)(?!$)/u', $str ); // return array of every multi-byte character
foreach ($ar as $c){
$o = ord($c);
if ( (strlen($c) > 1) || /* multi-byte [unicode] */
($o <32 || $o > 126) || /* <- control / latin weirdos -> */
($o >33 && $o < 40) ||/* quotes + ambersand */
($o >59 && $o < 63) /* html */
) {
// convert to numeric entity
$c = mb_encode_numericentity($c,array (0x0, 0xffff, 0, 0xffff), 'UTF-8');
}
$str2 .= $c;
}
return $str2;
}