DELPHI function for PHP

0

I'm reprogramming a system from a client and need to convert a function in Delphi to PHP to complete a system step and I'm having trouble with that ... could you give me a help .. thank you in advance .. follow the code below that needs to be converted to PHP:

Function CalcRegistro(Codigo: String): String;
Var vCod: Extended;
    vCnt, vAsc: LongInt;
    vStr: String[128];
Begin
    vCod:= 0;
    vStr:= Copy(Codigo + RepeatStr(' ',128), 1, 128);
    For vCnt := 1 to 128 do
    Begin
        vAsc:= Ord(vStr[vCnt]);
        vAsc:= (vAsc + (128-vCnt));
        vCod:= vCod + Power(vAsc,6);
    End;
    Result:= FloatToStrF(vCod, ffFixed, 16, 0);
End;
    
asked by anonymous 17.11.2017 / 03:03

1 answer

1

Two details: I do not remember a "Repeatstr" function in Delphi, so I switched to "stringofchar". Delphi has an initial index (in strings) in 1, unlike PHP where the initial index is 0, so I needed to adjust this. Here's the PHP function:

function CalcRegistro($Codigo)
{
$vCod=0;
$vStr= substr($Codigo . str_repeat(' ',128), 0, 128);
for ($vCnt = 0; $vCnt {
$vAsc= ord(substr($vStr,$vCnt,1));
$vAsc= ($vAsc + (128-$vCnt-1));
$vCod= $vCod + pow($vAsc,6);
}
return substr(str_replace(",","", number_format($vCod)),0,16);
}
    
17.11.2017 / 11:26