note 79272 added to function.shell-exec

From: Date: Mon, 19 Nov 2007 10:02:58 +0000
Subject: note 79272 added to function.shell-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-132393@lists.php.net to get a copy of this message
Even when external program returns an ISO-8859-1 encoded string, PHP "parses" the encoded string as ASCII, expanding accented characters as their literal string form and not their binary form. Basically, this mangles every accented character of the output from Windows external program. Below is how I fixed it for french accented characters: <?php echo shell_exec('echo éêèëàâäîïùûüôöç'); // The output of this will be something like: ‚ˆŠ‰…ƒ„Œ‹—–“”‡ // Not quite what was expected... // This is the function that fixes accented characters. function fix_string($str) { return strtr($str, chr(130).chr(136).chr(138).chr(137). chr(133).chr(131).chr(132).chr(140). chr(139).chr(151).chr(150).chr(129). chr(147).chr(148).chr(135), chr(233).chr(234).chr(232).chr(235). chr(224).chr(226).chr(228).chr(238). chr(239).chr(249).chr(251).chr(252). chr(244).chr(246).chr(231) ); } echo fix_string(shell_exec('echo éêèëàâäîïùûüôöç')); // We now get a proper output! ?> ---- Server IP: 62.73.197.23 Probable Submitter: 81.80.205.189 (proxied: 148.82.17.202) ---- Manual Page -- http://www.php.net/manual/en/function.shell-exec.php Edit -- https://master.php.net/note/edit/79272 Del: integrated -- https://master.php.net/note/delete/79272/integrated Del: useless -- https://master.php.net/note/delete/79272/useless Del: bad code -- https://master.php.net/note/delete/79272/bad+code Del: spam -- https://master.php.net/note/delete/79272/spam Del: non-english -- https://master.php.net/note/delete/79272/non-english Del: in docs -- https://master.php.net/note/delete/79272/in+docs Del: other reasons-- https://master.php.net/note/delete/79272 Reject -- https://master.php.net/note/reject/79272 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132393) next »