M
M
Maxim Shcherbakov2018-04-22 17:17:45
PHP
Maxim Shcherbakov, 2018-04-22 17:17:45

Why displays krakozyabry?

I use the code in PHP from under Windows 10

<?php
$data = 'help';
exec(escapeshellcmd($data), $output, $return);
echo implode("\n", $output)."\nReturn Code: $return";
?>
and it displays in the browser:
5adc98b51852f885742916.png
Why is this happening ??

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alexalexes, 2018-04-22
@UnknownError

If you use a PHP 5.6 server and higher, then you need to send an http header to the browser, in what encoding the script will give data, regardless of what encoding the script file itself is in, and even if you normally give the HTML structure of the document.

//установка кодировки вывода
  header('Content-Type: text/html; charset=utf-8');

If you do not know what encoding the data will be in, then you need to identify the encoding and enter it in the header(): --------------------------- - I selected the encoding for the header by typing, since mb_detect_encoding () did not display an explicit answer. I ended up with a CP866:
header('Content-Type: text/html; charset=CP866');
$data = 'help';
exec(escapeshellcmd($data), $output, $return);
echo implode("<br>", $output)."<br>Return Code: ".$return;

D
Denis, 2018-04-22
@sidni

and if so...

echo  iconv('UTF-8', 'windows-1251//TRANSLIT', implode("\n", $output))."\nReturn Code: $return";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question