Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of exec garbled codes in php

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to solve the problem of exec garbled code in php. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

Php exec garbled solutions: 1, the implementation of "exec (" python cmd.py ", $str);"; 2, through "iconv (" GBK "," UTF-8 ", $res);" way to transform the code.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

Php padding exec or shell_exec cannot return garbled codes in Chinese

I originally wanted to carry out:

Exec ("python cmd.py", $str); var_dump ($str)

The output of the cmd.py file contains Chinese, and the result is shown in the following figure:

Many bloggers say it can be solved by setting a predetermined code, such as adding the code before executing the command:

$locale='en_US.UTF-8';setlocale (LC_ALL,$locale); putenv ('LC_ALL='.$locale); exec ("python cmd.py", $str); var_dump ($str)

After trying, I found that the problem still existed and had no effect. After a long time after google finally found a solution, then do not dare to stay alone, post to share.

No nonsense, just go ahead.

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)

Above exec and shell_exec returns can be displayed in Chinese!

The above is all the contents of this article entitled "how to solve the problem of exec garbled in php". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report