I’m trying to change the php code to be compatible with php 8.2.12 from php 6.0.0-dev. The code deals with hexadecimal so I’m a little confused with the output.
Here’s an example of the result of the code that came out, php 8.2.12
i 0
i 0
H8 0 << questionable result
Warning: pack(): Type H: not enough characters in string in C:xampphtdocsservicesparserinclude.php on line 683
H8 16000000
H8 0d000000
Previously in the php 6.0.0-dev version the result was
i 0
i 0
i 0 << questionable result
H8 16000000
H8 0d000000
So the value of format i 0 before H8 16000000 in php 8.2.12 is changed to H8 0 which makes an error “Warning: pack(): Type H: not enough characters in string in C:xampphtdocsparserinclude.php on line 683”
Can anyone help with this problem? Here is the complete code of the parser function
function parser($output, $input, $indexing, $blockheader)
{
global $typearr, $stop_error_msg;
$filearray = file($input, FILE_SKIP_EMPTY_LINES);
$filesize = sizeof($filearray);
$struct = explode("t", trim($filearray[0]));
$col_names = explode("t", trim($filearray[1]));
if ($blockheader == 1)
{
// Define or replace strsize() function
// $block = strsize($struct);
$block = count($struct); // Example replacement
if ($indexing == 1)
$block += 4;
$filesize_bin = pack("i", ($filesize - 2));
fwrite($output, $filesize_bin);
$blockbin = pack("i", $block);
fwrite($output, $blockbin);
}
for ($i = 2; $i < $filesize; $i++)
{
$store = 0;
$temporary = explode("t", trim($filearray[$i]));
if ($indexing == 1)
fwrite($output, pack("i", $i - 2));
for ($st = 0; $st < count($struct) - 1; $st++)
{
if ($temporary[$st] == '')
{
$stop_error_msg .= "<br>Empty cell. Probably mistake at excel file:<br>ROW:".($i+1)."<br>COLUMN:".($st+1)."<br>NAME:".$col_names[$st]."<br>DATA:".$temporary[$st];
return false;
}
if (stristr($struct[$st], 'string[') !== false)
{
preg_match("/^(string[)?([d]+)/", $struct[$st], $str_ret);
if (strlen($temporary[$st]) >= $str_ret[2])
{
$temporary[$st] = substr($temporary[$st], 0, $str_ret[2] - 1);
echo "<br>Warning! Text overflow. Tail of string had been cut: ROW:".($i+1)." COLUMN:".($st+1)." NAME:".$col_names[$st]." DATA:'".$temporary[$st]. "' SIZE:". $str_ret[2];
}
//if(strlen($temporary[$st]) >= 255 && stristr($input, 'Desc') !== false)
// {
// echo "<br>Warning! Exceeded max length of 255 symbols at item description. Tail of string wont be shown in game: ROW:".($i+1)." COLUMN:".($st+1)." NAME:".$col_names[$st]." DATA:'".$temporary[$st]. "' SIZE:". $str_ret[2];
//$temporary[$st] = substr($temporary[$st], 0, 254);
// }
$resulthex = pack("a".$str_ret[2], trim(str_replace("x22x22x22x22", "x22x22", $temporary[$st]), "x22"));
fwrite($output, $resulthex);
continue;
}
$type = $typearr[$struct[$st]]['type'];
switch($type)
{
case "xeh":
$resulthex = xeh($temporary[$st]);
break;
case "xeh64":
$resulthex = xeh64($temporary[$st]);
break;
case "clcode":
$resulthex = clcode($temporary[$st]);
break;
case "exclcode":
if(($resulthex = exclcode($temporary[$st])) === false)
{
$stop_error_msg .= " Probably mistake at excel file:<br>ROW:".($i+1)."<br>COLUMN:".($st+1)."<br>NAME:".$col_names[$st]."<br>DATA:".$temporary[$st];
return false;
}
break;
case "ccode":
$resulthex = ccode($temporary[$st]);
break;
case "f":
case "d":
$trans = array("," => ".");
$resulthex = pack($type, strtr("".$temporary[$st]."", $trans));
break;
case "bulltype":
if(($resulthex = bulltype($temporary[$st])) === false)
{
$stop_error_msg .= " Probably mistake at excel file:<br>ROW:".($i+1)."<br>COLUMN:".($st+1)."<br>NAME:".$col_names[$st]."<br>DATA:".$temporary[$st];
return false;
}
break;
case "bttype":
if(($resulthex = bttype($temporary[$st])) === false)
{
$stop_error_msg .= " Probably mistake at excel file:<br>ROW:".($i+1)."<br>COLUMN:".($st+1)."<br>NAME:".$col_names[$st]."<br>DATA:".$temporary[$st];
return false;
}
break;
case "effbttype":
if(($resulthex = effbttype($temporary[$st])) === false)
{
$stop_error_msg .= " Probably mistake at excel file:<br>ROW:".($i+1)."<br>COLUMN:".($st+1)."<br>NAME:".$col_names[$st]."<br>DATA:".$temporary[$st];
return false;
}
break;
case "stb":
if(($resulthex = stb($temporary[$st])) === false)
{
$stop_error_msg .= " Probably mistake at excel file:<br>ROW:".($i+1)."<br>COLUMN:".($st+1)."<br>NAME:".$col_names[$st]."<br>DATA:".$temporary[$st];
return false;
}
break;
case "stb4":
if(($resulthex = stb4($temporary[$st])) === false)
{
$stop_error_msg .= " Probably mistake at excel file:<br>ROW:".($i+1)."<br>COLUMN:".($st+1)."<br>NAME:".$col_names[$st]."<br>DATA:".$temporary[$st];
return false;
}
break;
case "stb12":
if(($resulthex = stb12($temporary[$st])) === false)
{
$stop_error_msg .= " Probably mistake at excel file:<br>ROW:".($i+1)."<br>COLUMN:".($st+1)."<br>NAME:".$col_names[$st]."<br>DATA:".$temporary[$st];
return false;
}
break;
case "stb16":
if(($resulthex = stb16($temporary[$st])) === false)
{
$stop_error_msg .= " Probably mistake at excel file:<br>ROW:".($i+1)."<br>COLUMN:".($st+1)."<br>NAME:".$col_names[$st]."<br>DATA:".$temporary[$st];
return false;
}
break;
case "res":
$resulthex = resource($temporary[0]);
break;
case "qitid":
$resulthex = qitid($temporary[$st]);
break;
case "lqitem":
$resulthex = lqitem($temporary[$st]);
break;
case "store":
if(($resulthex = store($temporary[$st], $store, $temporary[10])) === false)
{
$stop_error_msg .= " Probably mistake at excel file:<br>ROW:".($i+1)."<br>COLUMN:".($st+1)."<br>NAME:".$col_names[$st]."<br>DATA:".$temporary[$st];
return false;
}
$store++;
break;
case "qcode":
$resulthex = qcode($temporary[$st]);
break;
case "spcode":
$resulthex = spcode($temporary[$st]);
break;
case "text":
$len = strlen($temporary[$st]);
$len = $len + 1;
$resulthex=pack("a".$len, $temporary[$st]);
$plen=pack("i", $len);
fwrite($output, $plen);
break;
case "param":
if(($resulthex = param($temporary[$st], $temporary[$st+1])) === false)
{
$stop_error_msg .= " Probably mistake at excel file:<br>ROW:".($i+1)."<br>COLUMN:".($st+1)."<br>NAME:".$col_names[$st]."<br>DATA:".$temporary[$st];
return false;
}
$st++;
break;
default:
echo $type." ".$temporary[$st]."<br>";
$resulthex = pack($type, $temporary[$st]); # error indication is in this script
}
if(!empty($err_arr) && isset($err_arr['message']) && stripos($err_arr['message'], 'function.date') !== false) {
$stop_error_msg .= "<br>Pack error. Probably mistake at excel file:<br>ROW:".($i+1)."<br>COLUMN:".($st+1)."<br>NAME:".$col_names[$st]."<br>DATA:".$temporary[$st];
return false;
}
fwrite($output, $resulthex);
}
}
return true;
}
I just tried to change the value of the $type variable to fix for the i format, but the result is still messy
default:
echo "i" ".$temporary[$st]."<br>";
$resulthex = pack("i", $temporary[$st]); # error indication is in this script
i0
i0
i0 << questionable result
i16000000 << changed to i format
i0d000000 << changed to i format
Do I need to add a new function to handle H8 format and make a separate case instead of default?