Re[2]: [PHP] How does unpack works?
| From: | Tom Rogers | Date: | Tue, 21 Oct 2003 05:38:34 +0000 |
| Subject: | Re[2]: [PHP] How does unpack works? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-166900@lists.php.net to get a copy of this message | ||
Hi,
Tuesday, October 21, 2003, 3:36:35 PM, you wrote:
TR> Hi,
TR> Tuesday, October 21, 2003, 3:12:47 PM, you wrote:
VE>> Hi,
VE>> I'm trying to extract an binary file with unpack but I don't understand
VE>> how it works...
VE>> The F6FBB program makes the file...
VE>> It is a hamradio program http://www.f6fbb.org/
VE>> This is the structure of 1 record in the file :
VE>> struct inf_struct
VE>> { char callsign[8]; /* Callsign */
VE>> char dummy1[64];
VE>> long lastmes;
VE>> long connects; /* Number of connexions */
VE>> long hcon;
VE>> long lastyap;
VE>> int flags;
VE>> int on_base;
VE>> char nbl;
VE>> char lang;
VE>> long newbanner;
VE>> int download;
VE>> char free[20];
VE>> char thema;
VE>> char nom[18];
VE>> char prenom[13];
VE>> char adres[61];
VE>> char ville[31];
VE>> char teld[13];
VE>> char telp[13];
VE>> char home[41];
VE>> char gra[7];
VE>> char priv[13];
VE>> char filtre[7];
VE>> char pass[13];
VE>> char zip[1];
VE>> } inf; /* 360 bytes = lenght of one record */
VE>> Can somebody help me?
VE>> Regards,
VE>> Vincent
TR> Try this (assumes little endian byte ordering, if big endian V = N v = n)
TR> $array = unpack("
TR> a8callsign/
TR> a64dummy1/
TR> Vlastmes/
TR> Vconnects/
TR> V/hcon/
TR> V/lastyap/
TR> vflags/
TR> von_base/
TR> cnbl/
TR> clang/
TR> Vnewbanner/
TR> vdownload/
TR> a20free/
TR> cthema/
TR> a8nom/
TR> a13prenom/
TR> a61adres/
TR> a31ville/
TR> a13teld/
TR> a13telp/
TR> a41home/
TR> a7gra/
TR> a13priv/
TR> a7filtre/
TR> a13pass/
TR> czip",$input);
TR> print_r($array);
TR> --
TR> regards,
TR> Tom
oops .. some stray / in there
$array = unpack("
a8callsign/
a64dummy1/
Vlastmes/
Vconnects/
Vhcon/
Vlastyap/
vflags/
von_base/
cnbl/
clang/
Vnewbanner/
vdownload/
a20free/
cthema/
a8nom/
a13prenom/
a61adres/
a31ville/
a13teld/
a13telp/
a41home/
a7gra/
a13priv/
a7filtre/
a13pass/
czip",$input);
print_r($array);
--
regards,
Tom