Hi. I’ve encountered a couple of issues with the handling of ASCII and EBCDIC in PHP 7 (these examples work correctly in PHP 5). I have PHP 7 CGIs working successfully using the requires environment variables and IHS definitions but these specific situations don’t seem to correctly handle the conversion of character sets.
The first is the exec() function. This can return an array of output generated by the externally called program. I have a PHP script calling a REXX script with the REXX returning multiple lines of output via the SAY statement. When the output arrives back to PHP it appears to be ASCII encoded EBCDIC and the array is not correctly populated.
Here is the PHP script called exec1:
#!/ported/php/bin/php-cgi
<?php
if($_GET["conv"]=="yes")
$p=" | iconv -f IBM-1047 -t ISO8859-1";
else
$p="";
$output=array();
exec("./exec2 input one".$p,$output,$rc);
echo "RC=$rc";
echo "<br />output[0]=".$output[0];
echo "<br />output[1]=".$output[1];
echo "<br />output[2]=".$output[2];
echo "<br />output[0]=".iconv("IBM-1047","ISO8859-1",$output[0]);
echo "<br />output[1]=".iconv("IBM-1047","ISO8859-1",$output[1]);
echo "<br />output[2]=".iconv("IBM-1047","ISO8859-1",$output[2]);
?>
Here is the external REXX called exec2:
/*rexx*/
parse arg in
say "hello world"
say in
say "last line"
exit 4
Navigating to exec1 in the browser shows that all of the exec2 output lines are placed as a single string in the first element of array $output and the string is EBCDIC so doesn’t display very well. Adding query string exec1?conv=yes passes exec2 output through iconv and $output is then populated correctly (this is not a very good solution). It seems as though the exec() function isn’t handling character conversion correctly as the output generated by REXX exec2 is EBCDIC.
The second situation involves POSTing form data back to the PHP script. It is also coming back as EBCDIC (probably due to IHS processing) and consequently the PHP $_POST superglobal is not populated correctly. Here is an example PHP script called testpost:
#!/ported/php/bin/php-cgi
<?php
$cginame=$_SERVER["PHP_SELF"];
echo "<form action=\"$cginame\" method=\"post\" name=\"form1\">\n";
echo "<br /><strong>Edit1:</strong>";
echo "<input type=\"text\" value=\"".$_POST["edit1"]."\" ".
"name=\"edit1\" size=\"20\">\n";
echo "<br /><strong>Edit2:</strong>";
echo "<input type=\"text\" value=\"".$_POST["edit2"]."\" ".
"name=\"edit2\" size=\"20\">\n";
echo "<br /><input type=\"submit\" value=\"Refresh\" name=\"refresh\">\n";
echo "</form>\n";
echo "<br />Edit1: ".$_POST["edit1"];
echo "<br />Edit2: ".$_POST["edit2"];
echo "<br />";
print_r($_POST);
foreach($_POST as $n=>$v)
echo "<br />".iconv("IBM-1047","ISO8859-1",$n).",$v";
?>
It’s not beautiful to look at but when run in the browser it shows that $_POST contains all of the variable information as a single string in a single array element. The script also passes $_POST through iconv to show that the data is actually EBCDIC by converting it to ASCII.
It’s most likely that something is misconfigured somewhere but it’s not clear what that might be so any guidance is appreciated.
Richard.