note 91577 added to function.shell-exec
| From: | JoeriSebrechts at osu1 dot php dot net | Date: | Wed, 17 Jun 2009 14:27:22 +0000 |
| Subject: | note 91577 added to function.shell-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156987@lists.php.net to get a copy of this message | ||
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;
?>
----
Server IP: 209.41.74.194
Probable Submitter: 81.246.42.194
----
Manual Page -- http://www.php.net/manual/en/function.shell-exec.php
Edit -- https://master.php.net/note/edit/91577
Del: integrated -- https://master.php.net/note/delete/91577/integrated
Del: useless -- https://master.php.net/note/delete/91577/useless
Del: bad code -- https://master.php.net/note/delete/91577/bad+code
Del: spam -- https://master.php.net/note/delete/91577/spam
Del: non-english -- https://master.php.net/note/delete/91577/non-english
Del: in docs -- https://master.php.net/note/delete/91577/in+docs
Del: other reasons-- https://master.php.net/note/delete/91577
Reject -- https://master.php.net/note/reject/91577
Search -- https://master.php.net/manage/user-notes.php