What is the use of mb_http_output (), given that output coding is usually fixed in other ways?

Throughout the Internet, including stackoverflow, it is suggested to use mb_http_input ('utf-8') so that PHP works in UTF-8 encoding. For example, see Problems with PHP / MySQL Encoding. instead of certain characters . On the other hand, the PHP manual says that we cannot fix the input encoding in the PHP script and that mb_http_input is just a way to request what it is and not a way to install it. See http://www.php.net/manual/en/mbstring.http.php and http://php.net/manual/en/function.mb-httpetinput.php. Well, this is just a clarification of the context before the question. It seems to me that in Apache + PHP + HTML there are many redundant commands for controlling the conversion from the input encoding to the internal encoding and, finally, to the output encoding. I do not understand the usefulness of this. For example, if the source encoding of the input from some external HTTP client is EUC-JP, and I set the internal encoding to UTF-8, then PHP would have to do the conversion. I'm right? If I am right, why should I enter the input encoding in php.ini (and not just pass the original one), given that it will be immediately converted to the internal utf-8 encoding? A similar question remains for exit. In all my htpp files, I use a meta tag with charset = utf-8. Thus, the final HTTP encoding is fixed. Moreover, in PHP.ini I can set default_charset,which will be displayed in the HTTP header in utf-8. Why don't I use mb_http_output ('uft-8') when the final output encoding is already fixed. To summarize, can someone give me a practical concrete example where mb_http_output ("uft-8") is clearly necessary and cannot be replaced with more ordinary commands that are often inserted by default in editors such as Dreamweaver?

+5
source share
1 answer

These two options are the worst idea PHP developers have ever come across, and they had a lot of bad ideas when it came to encodings.

To convert strings to a specific encoding, you need to know from which encoding it is converted. Incoming data is often in undeclared encoding; the server just receives some binary data, it does not know what encoding it represents. You must declare what encoding you expect from sending the browser by setting the attribute accept-charsetfor the forms; this does not guarantee that the browser will do this, nor will it force PHP to know what encoding to expect.

; PHP - -, . , PHP , .

, : , , , , mb_check_encoding ( _detect encoding , ), , , . I.e., .

, Unicode: UTF-8 Unicode , . , , , , . " UTF-8" .

+9

All Articles