The solution to the Chinese garbled code in form submission in php is: you can set the webpage encoding through the head() function to solve the problem. The specific method is: add content [header("Content-Type: text/html; charset=UTF-8");] to the header of the php file.
Solution:
(Recommended tutorial: php tutorial)
1 . Add the following code to the head in HTML:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
2. Make sure all files are utf8 encoded.
3. Add the following code to the header of the php file:
header("Content-Type:text/html; charset=UTF-8");
This should avoid the problem of Chinese garbled characters.
Related function introduction:
The header() function sends the original HTTP header to the client. The header() function must be called before any actual output is sent (in PHP 4 and later, you can use output buffering to solve this problem).
Function syntax:
header(string,replace,http_response_code)
Parameter description:
string Required. Specifies the header string to be sent.
replace Optional. Indicates whether this header replaces the previous header, or adds a second header. Default is TRUE (replacement). FALSE (allow multiple headers of the same type).
http_response_code Optional. Forces the HTTP response code to the specified value. (Available in PHP 4.3 and above)
The above is the detailed content of How to solve the problem of Chinese garbled characters in form submission in PHP. For more information, please follow other related articles on the PHP Chinese website!