简体   繁体   English

htmlspecialchars()函数中的utf-8

[英]utf-8 in htmlspecialchars() function

I have a slight confusion regarding using UTF-8 in the htmlspecialchars() function like this: 关于在htmlspecialchars()函数中使用UTF-8,我有些困惑:

htmlspecialchars($string, ENT_QUOTES, 'UTF-8');

What I do not understand is, does using this make htmlspecialchars() create a UTF-8 code or that it just informs htmlspecialchars() the $string is UTF-8 so that it does not mess up. 我不明白的是,是否使用此命令使htmlspecialchars()创建一个UTF-8代码,或者它只是通知htmlspecialchars()$ string为UTF-8,所以它不会弄乱。 I mean are we specifying? 我的意思是我们要指定吗? the input or are we specifying the output? 输入还是我们指定输出?

Hope it makes sense. 希望有道理。 Thank you. 谢谢。

The third parameter is for both input and output. 第三个参数用于输入输出。 If you want to convert between character sets, you'll have to do it externally eg using the iconv function. 如果要在字符集之间进行转换,则必须从外部进行操作,例如使用iconv函数。

The third parameter is just to tell htmlspecialchars() not to mess up Unicode strings. 第三个参数只是告诉htmlspecialchars()不要弄乱Unicode字符串。 You need to tell htmlspecialchars() what the input encoding is. 您需要告诉htmlspecialchars()输入的编码是什么。 Consequentially, that is also the encoding used in the output. 因此,这也是输出中使用的编码。

Remember that PHP does not support Unicode, so it does not care about what charset you are using. 请记住,PHP不支持Unicode,因此它并不在乎您使用的是什么字符集。 That parameter in htmlspecialchars() is only used to tell PHP not to mess up with your bytes. htmlspecialchars()中的该参数仅用于告诉PHP不要弄乱您的字节。

I think the manual is straight forward about this 我认为手册对此很直接

Defines encoding used in conversion. 定义转换中使用的编码。 If omitted, the default value for this argument is ISO-8859-1 in versions of PHP prior to 5.4.0, and UTF-8 from PHP 5.4.0 onwards. 如果省略,则此参数的默认值在5.4.0之前的PHP版本中为ISO-8859-1,从PHP 5.4.0起使用UTF-8。

This is about input and output. 这是关于输入和输出的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM