I have a very old code that now needs to be made PHP 8 executable, unfortunately I'm stuck with what should be a simple task.
How can I solve the problem in line 17. array and string offset access syntax with curly braces is no longer supported.
//convert a string to a 32-bit integer
function StrToNum($Str, $Check, $Magic)
{
$Int32Unit = 4294967296; // 2^32
$length = strlen($Str);
for ($i = 0; $i < $length; $i++) {
$Check *= $Magic;
//If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31),
// the result of converting to integer is undefined
// refer to http://www.php.net/manual/en/language.types.integer.php
if ($Check >= $Int32Unit) {
$Check = ($Check - $Int32Unit * (int)($Check / $Int32Unit));
//if the check less than -2^31
$Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
}
$Check += ord($Str{$i});
}
return $Check;
}
My first thought is that you can use the Strig. Or the array accordingly defined before. Am I right there?
Update Solution: Changed ($Str{$i} to ($Str[$]}. Solved.