Hello all,
I have some PHP scripts that need to communicate to a server running some apps that returns mostly text, except for one parameter at the very beginning - a record length, which is a C-Short data type.
If everything else is text, then I just need to figure out how to parse this C-short data type variable's value before being able to find out where the rest of the text is but need some advice as how to go about doing this.
One simple workaround is to have the apps be modified so that they return this length in plain text but that's not possible.
Any help would be greatly appreciated!
Thanks
C Short data type and PHP
Moderator: General Moderators
Re: C Short data type and PHP
So you're getting two bytes representing a C-style short int?
Use ord to get the numerical value of a byte. Then it's just some base-256 conversion.
Ah, right, unpack... I thought I was forgetting something
Use ord to get the numerical value of a byte. Then it's just some base-256 conversion.
Code: Select all
Long int \x12\x34\x56\x78 => characters 18, 52, 86, 120
Big endian: 18 * 256^3 + 52 * 256^2 + 86 * 256^1 + 120 * 256^0 = 305419896
Little endian: 18 * 256^0 + 52 * 256^1 + 86 * 256^2 + 120 * 256^3 = 2018915346
Last edited by requinix on Thu Jan 21, 2010 3:07 am, edited 1 time in total.