DELPHI function for PHP

Asked

Viewed 218 times

0

I am reprogramming a client system and I need to convert a function in Delphi to PHP to complete a system step and I am struggling with it... could give me a help.. thanks 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;
  • PHP is basically untyped. A lot of it turns out that it’s not translated into PHP. Have you tried doing anything?

  • The problem is precisely with these functions of Delphi, "Ord" and "Power".. never worked with Delphi...

  • The function that this having difficulty is in System.Math, in your example are using basic Delphi functions.

1 answer

1


Two details: I don’t remember there being 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 had to adjust this. Follow the function in PHP:

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);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.