Home >Backend Development >PHP Problem >What to do if bat executes php Chinese garbled code

What to do if bat executes php Chinese garbled code

藏色散人
藏色散人Original
2022-11-09 09:39:261789browse

Solution for bat to execute php Chinese garbled code: 1. Use the Notepad that comes with the Windows operating system platform to open the script file; 2. Click the menu [File] - [Save As] operation; 3. Select ANSI encoding Save; 4. Declare the code page change in the original bat script file.

What to do if bat executes php Chinese garbled code

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

What should I do if bat executes Chinese garbled code in php?

bat batch script solution to Chinese garbled characters

Problem description

bat batch script is as follows

@echo off

echo hello,world.
echo 你好,中国

pause

When CMD executes the script, Chinese garbled characters

Problem analysis

  • Garbled characters are all related to character encoding.
  • The computer can only process numbers. If it encounters text, it must be converted into numbers before it can be processed. This is where character encoding (character set) appears. If a certain character encoding is used for encoding, the same character encoding must be used for decoding. If different character encodings are used, garbled characters will appear.

Problem Solving

1. Convert the encoding method of the script file

By default, in the bat script file, if the Chinese is not ANSI encoding, it will appear Garbled characters. Therefore, you can use the Notepad that comes with the Windows operating system platform to open the script file, click the menu [File] - [Save As], and select ANSI encoding to save.

After converting the encoding and running it again, the Chinese garbled problem is solved.

2. Change the code page

Declare the code page change in the original bat script file

chcp 65001

Run again, the Chinese garbled problem is solved.

Extensionchcp Command

Changes the active console code page.

Commonly used Code page mapping

Code page Mapped character set
936 GB2312
20127 US-ASCII
65001 UTF-8

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if bat executes php Chinese garbled code. 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