How can the output character encoding of a program called with shell_exec be converted to match the encoding of a PHP script?

When using shell_exec to run a program in PHP, the output may be in a different character encoding than the PHP script itself. To convert the output encoding to match the PHP script encoding, you can use the iconv function in PHP. This function allows you to convert strings between different character encodings.

// Run the program using shell_exec
$output = shell_exec('your_program_here');

// Convert the output encoding to match the PHP script encoding
$output = iconv("output_encoding", "script_encoding", $output);

// Now $output will be in the same encoding as the PHP script