Re: Problem using unpack

From: Date: Sun, 20 May 2001 10:02:06 +0000
Subject: Re: Problem using unpack
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-53602@lists.php.net to get a copy of this message
$playerdata = unpack('czero/A'.$length.'one/itwo/fthree/A*four', $rest); Good Luck! --Zak ----- Original Message ----- From: "Craig Vincent" <2bunnyhop@home.com> To: <php-general@lists.php.net> Sent: Sunday, May 20, 2001 4:00 AM Subject: [PHP] Problem using unpack > 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 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#53602) next »