note 91577 deleted from function.shell-exec by danbrown

From: Date: Wed, 17 Jun 2009 14:28:26 +0000
Subject: note 91577 deleted from function.shell-exec by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156988@lists.php.net to get a copy of this message
Note Submitter: Joeri Sebrechts ---- This comment is specific to windows systems and in reply to mandor's comment on character set issues. The shell works in a different character set (CP437 in the US, and CP850 in western europe) than the regular ANSI character set (ISO-8859-1), which is again different from what you normally would want to be using in PHP (UTF-8). The result value from the shell command is in the DOS code page. You can see this by typing "chcp" on the prompt. In my case this was 850, which to iconv is known as "CP850". However, the input value PHP passes to this script is converted somewhere along the way. It requires not the DOS code page, but the ANSI code page that corresponds to it ("ISO-8859-1") The following script produced the correct result when saved as UTF-8 on a php installation with UTF-8 default character set (tested in firefox): <?php // returns correct result on a western-european windows installation (Dutch / Belgium) header("Content-type: text/plain"); $PHPCharSet = ini_get("default_charset"); $DOSCharSet = "CP850"; $ANSICharSet = "ISO-8859-1"; $source = "éêèëàâäîïùûüôöç"; $source = iconv($PHPCharSet, $ANSICharSet, $source); $result = shell_exec("echo ".$source); echo "Initial: " . $result . "\n"; $result = iconv($DOSCharSet, $PHPCharSet, $result); echo "Converted: " . $result; ?>

« previous php.notes (#156988) next »