Re: Reading with C 'struct' data

From: Date: Wed, 08 Aug 2001 01:04:10 +0000
Subject: Re: Reading with C 'struct' data
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-61937@lists.php.net to get a copy of this message
> struct BACACHE > > char author[300][100]; > int top; > time_t uptime; > time_t touchtime; > int busystate; > }; > > is there any way to get these data into PHP with certain variable type ? > > I've tried to use " unpack() " function, but I found that unpack() can't > unpack a char array ( I mean string) , it breaks string into characters.... > please help me... Almost for sure you're going to have to read it byte-by-byte and parse it... Here's a start: <?php $path = '/path/to/bacache.xxx'; # 'b' is only needed on Windoze, but shouldn't hurt Un*x $file = fopen($path, 'rb') or die("Could not open $path"); while (!feof($path)){ $author = fread($file, 300*100); # You may or may not need to convert each byte somehow... # Is a C int 2 or 4 bytes this week? Sigh. $top = fread($file, 4); # Now, *THAT* almost for sure needs converting... # Maybe you'll be lucky and hexdec will do it... $uptime = fread($file, 4); $touchtime = fread($file, 4); $busystate = fread($file, 4); } ?> You'd probably want all sorts of error-checking in there... -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#61937) next »