Problem using unpack

From: Date: Sun, 20 May 2001 10:00:22 +0000
Subject: Problem using unpack
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-53600@lists.php.net to get a copy of this message
I'm current trying to use PHP's unpack feature to decode a binary string and am running into a problem. Here is the unpack command I am using $playerdata = unpack("czero/A$lengthone/itwo/fthree/A*four", $rest); basically it is setup so that the hash created has 5 key/value pairs named zero, one, two, three and four. However my problem is with the second key/value pair. Since the information I need for the second field is dynamic I need to be able to set a variable there to tell PHP exactly how many characters are to be parsed for that field. So say $length = 5 right now the command would be translated by PHP as $playerdata = unpack("czero/A5one/itwo/fthree/A*four", $rest); At least that's what I need =) The problem I'm experiencing right now is that PHP translates the variable as $lengthone instead of just $length which of course always results in 0 and then causes the data to be parsed incorrectly. I cannot use whitespace to separate $length and one as then the unpack feature breaks down thinking that whitespace should be in the string I'm unpacking which messes things up as well. Any suggestions/tips for handling this problem would be much appreciated =) I've been plagued with this problem for a few days now and I'm having no luck =/ Sincerely, Craig Vincent

« previous php.general (#53600) next »