Skip to content
Harry's Blog
  • About Me
  • Blog

Fix CMD output when using shell_exec() from PHP

December 19, 2019
/**
 * Fix weird output encoding.
 */
function run_command($command) {
    $string = shell_exec($command);
    $string = mb_convert_encoding($string, 'UTF-8', 'UTF-16LE');

    return $string;
}

Source: https://www.reddit.com/r/PHPhelp/comments/de27u8/why_output_of_shell_exec_is_different/f2uwy7s

Tags PHP
Post navigation
HARRY • 2023