2
<?php

header("Content-Type: text/plain; charset=UTF-8");  // output as text file
header("Content-Type: text/html; charset=UTF-8");   // output as HTML 
header("Accept-Charset: utf-8");
mb_internal_encoding('UTF-8');

$output_file = 'C:\\junk.txt';
$input = $argv[1];

file_put_contents($output_file, 'я ' . mb_detect_encoding($argv[1]) . ': ' . $argv[1]);
return;

?>

On the command prompt:

php C:\test.php я

The resulting file:

я ASCII: ?

I've tried changing the code page to 65001, that didn't help. How in the world do I pass a unicode character to PHP from the command prompt? It just assumes everything is ASCII. I'm expecting it to print out:

я UTF-8: я
Andrew
  • 1,571
  • 17
  • 31
  • It night be unrelated to your problem but [mb_detect_encoding()](http://php.net/mb_detect_encoding) is normally not as useful as it seems. Good old [bin2hex()](http://php.net/bin2hex) tends to be a better diagnose tool for encoding issues. – Álvaro González Jun 20 '13 at 16:18
  • 1
    I added `bin2hex($argv[1])` and it shows 3f. It literally thinks it's a question mark... – Andrew Jun 20 '13 at 16:28
  • I've been faced to this several times and I reached the conclusion that Windows command prompt simply does not support UTF-8 at all (no matter that a [65001 codepage](http://stackoverflow.com/questions/1629437/is-codepage-65001-and-utf-8-the-same-thing) exists). Let's wait and hopefully see other opinions. – Álvaro González Jun 20 '13 at 16:31

0 Answers0