Home Backend Development PHP Problem How to solve the problem of Chinese garbled characters in form submission in PHP

How to solve the problem of Chinese garbled characters in form submission in PHP

Jul 21, 2020 pm 02:12 PM
php Chinese garbled form

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.

How to solve the problem of Chinese garbled characters in form submission in PHP

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">
Copy after login

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");
Copy after login

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)
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles