views:

810

answers:

2

Everything is in the question : I have a Php script that is a UTF-8 file. In this script I want to do this :

  <?
  echo "âêïû\n";
  ?>

If I run it in a MSDOS prompt I get this :

C:\php>php -c C:\WINDOWS\php.ini -f mysqldump.php
âêïû
C:\php>

I've not been able to find the right conversion scheme. I've tried also this code :

$tab = mb_list_encodings();
foreach ($tab as $enc1) {
  foreach ($tab as $enc2) {
    $t=mb_convert_encoding("âêïû\n", $enc1, $enc2);
    if (strlen($t)<14) {
      echo $enc1." ".$enc2." = ".$t."\n";
    }
  }
}

And I didn't find the right conversion !

Any help would be greatly appreciated

+1  A: 

The problem is Windows cmd line by default does not support UTF8. From this link, if you follow these

  1. Open a command prompt window
  2. Change the properties of the window to use something besides the default raster font. he Lucida Console True Type font seems to work well.
  3. Run "chcp 65001" from the command prompt

You should be able to output utf8.

Doug T.
+1 Good to know that you can change the encoding in the shell
Peter Bailey
Okay I've tried "chcp 65001". Now each time I run "php -c C:\WINDOWS\php.ini -f mysqldump.php | more" I get a "Out of memory error". Then I try without the " | more" (this was too risky for Windows I guess grrr) and the script stops itself at the beginning...
Olivier Pons
can you try just "echo 'hello world'; "?
Doug T.
Please note that the default character set of the Windows command line is **NOT** ISO-8859-1 but rather Windows-1252 (at least for Latin1 / Western Europe).
Stefan Gehrig
A: 

You put me on the right track but there was kinddof a problem (I love Windows \o/) :

C:\php>chcp 65001
Page de codes active : 65001
C:\php>php -c C:\WINDOWS\php.ini -f mysqldump.php | more
Mémoire insuffisante.

Mémoire insuffisante = not enough memory.

If I try

C:\php>chcp 1252
C:\php>php -c C:\WINDOWS\php.ini -f mysqldump.php
C:\php>ééîîïïÂÂÂÂâûü

it works. Only God knows why. But it works. Thanks for putting me on the right track !!

By the way the php code to go properly form UTF8 to command prompt is :

  echo mb_convert_encoding($utf8_string, "pass", "auto");
Olivier Pons
You're sure that your `mysqldump.php` is UTF-8 encoded?
Stefan Gehrig
µYep I'm sure, I'm using it on www.acarat.com which is full utf-8 site
Olivier Pons