Cannot convert string to int in PHP -
i'm having tough time converting value read socket connection integer. it's value tells me how many bytes going received next.
$ar = fread($client, 4); $binaryint = unpack('n', $ar); debug_to_console($binaryint); //displays 16 (as expected) $bred = fread($client, intval($binaryint)); //intval returns 1
for reason intval evaluates 1 , can't figure out why. btw $ar variable sent integer java server have running via code sample
dout.writeint(data.length);
thanks
edit
i got it. user2587326 below helped instead of using intval(binaryint[1]) binaryint[1].
i think reading 4-byte integer sent java program on dataoutputstream php program on socket.
first, fread($client, 4) call reads 4 bytes string, convert them array unpack(), taking 4-bytes @ time (format specifier 'n') resulting array 1 element, use:
intval($binaryint[1]) instead of intval($binaryint) obtain number.
edit: works intval too, won't hurt it.
Comments
Post a Comment