Home  >  Article  >  Backend Development  >  What should I do if PHP receives garbled post parameters?

What should I do if PHP receives garbled post parameters?

藏色散人
藏色散人Original
2020-09-03 09:43:302963browse

Solution to php receiving garbled post parameters: First open the PHP file; then change the "header" code to "echo '

What should I do if PHP receives garbled post parameters?

Recommended: "PHP Video Tutorial"

Solution to php receiving garbled post parameters:

Specific problem:

PHP $_POST submits Chinese garbled characters

html:

{$pro_name}

价格:¥{$pro_price}

已售出:{$pro_sale}件 数量
action: public function add(){ $user = session("user_name"); if(session("user_name")){ header("Content-Type:text/html;charset=utf8"); request.setCharacterEncoding("UTF-8"); $common = D("Common"); $data["user_id"] = $user[0]["user_id"]; $data["user_name"] = $user[0]["user_name"]; $data["pro_id"] = $_POST["pro_id"]; $data["pro_name"] = $_POST["pro_name"]; $data["pro_price"] = $_POST["pro_price"]; $data["pro_num"] = $_POST["pro_num"]; $data["pro_total"] = $_POST["pro_num"]*$_POST["pro_price"]; dump($data); echo $data["pro_name"]; } }

Why is the received $_POST["pro_name"] garbled? I checked the source code of the page and the hidden field is not garbled

Solution:

header("Content-Type:text/html;charset=utf8");

Modify to

echo '';

The above is the detailed content of What should I do if PHP receives garbled post parameters?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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