Solution to garbled php exec results: 1. Open the corresponding PHP code file; 2. Check the code at exec; 3. Modify the content to "exec("python cmd.py",$str); foreach($str as $res){$str = iconv("GBK", "UTF-8", $res);}echo $str;".

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
What should I do if the php exec result is garbled?
php Fill in the pit exec or shell_exec cannot return Chinese garbled characters
Originally wanted to execute:
exec("python cmd.py",$str);
var_dump($str);The cmd.py file output contains Chinese, and the result is displayed It is shown in the picture below:

After searching on Baidu and csdn, many bloggers said that it can be solved by setting a predetermined encoding. For example, add the encoding before executing the command and then execute:
$locale='en_US.UTF-8';
setlocale(LC_ALL,$locale);
putenv('LC_ALL='.$locale);
exec("python cmd.py",$str);
var_dump($str);After trying it, I found that the problem still exists and it has no effect. . After a long search on Google, I finally found the solution, so I didn't dare to leave it alone, so I posted it to share. . No nonsense, just go straight to it. . .
exec:
exec("python cmd.py",$str);
foreach($str as $res)
{
$str = iconv("GBK", "UTF-8", $res);
}
echo $str;shell_exec:
$res = shell_exec("python cmd.py");
echo iconv("GBK", "UTF-8", $res);Recommended study: "PHP Video Tutorial"
The above is the detailed content of What to do if php exec results are garbled. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use






