Re: PHP to read binary file created with vba

From: Date: Wed, 04 Oct 2000 14:24:31 +0000
Subject: Re: PHP to read binary file created with vba
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-2934@lists.php.net to get a copy of this message
Shane: The random file you generated from VBA is a string of characters, in which each variable occupies certain amount of bytes depending on its type: byte = 1 character integer = 2 characters long = 4 characters string = n characters (n = string length) If you need to extract a byte, you read one character; if you need an integer, you read two characters and if you need a long, you get four characters. To get the string, you read the necesary amount of bytes according to its length. So, the file you described would look like this: |---20--||---50--| LLLLSSS...SSSSSS...SSSB... The string, you allready know how to get. For the other types you will need to read this bytes in several variables lets say $c1, $c2, $c3 and $c4. Then you will convert each character to its ordinal value: $v1=ord($c1); $v2=ord($c2); $v3=ord($c3); $v4=ord($c4); and finally you get your values: $byte = $v1; $integer = $v1 + $v2*256; $long = $v1 + $v2*256 + $v3*65536 + $v4*16777216; This constants are simply: 2^8, 2^16 and 2^24. Integer and Long values are saved in memory or files, with their bytes in reversed order, that is, first the least significant byte (LSB), then the next significant bytes (for Long values) and last the most significant byte (MSB). If your file contains other types, like single, double or currency, you will need to investigate the format of these values. I hope my explanation is clear enough. Saludos, Pablo Vera _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Wednesday, October 04, 2000, 4:41:41 AM, Shane wrote: S> Hi S> I have a binary file (Random mode) that was created using Excel/VBA with a S> record definition some thing like... S> Type Record S> account As Long S> contact As String * 20 S> custname As String * 50 S> directory As Byte S> . S> . S> . S> End Type S> I want to read,filter and display this file using PHP. S> So far I can extract and display the string fields ok but I don't know how S> the convert the Long or byte fields so they can be displayed S> Any suggestions? S> Shane.

« previous php.windows (#2934) next »