I am converting some Pascal to PHP. Inside a function of return type AnsiString
there are the following lines of code:
SetLength(Result, 3);
Move(I, Result[1], Length(Result));
I
is a Longint
with value 5051253. What ends up in Result
is 'u'#19'M'
.
How do I replicate that in PHP? What is it doing? I know Move
reads bytes from I
and puts them in Result
.
function low3bytes( $I) {
return chr( $I % 256)
. chr( ((int) ($I / 256)) % 256)
. chr( ((int) ($I / 65536)) % 256);
}
Caveat: Not tested.
The first line sets the length of variable "Result" to 3 bytes.
I don't know where the value of I comes from, but it is pointing to another variable in memory probably.
Second line is copying 3 bytes from that pointed memory area into variable "Result".
What you need to do is to look at where that variable "I" points to and build up the PHP code according to that.
Let's say, I refers to another ansistring variable "Source". Then you can do that:
`$Result = substr($Source, 0, 3);'