packing and unpacking question

Discussion in 'PHP' started by forelmashi, Dec 31, 2007.

  1. #1
    So without giving boring details, when I unpack a bunch of stuff and then re-pack it together, it works.

    But when I unpack a bunch of stuff and then re-pack it in order separately, it doesn't work.

    WhY??!!??

    Example:
    $this->header = unpack('Lheader_size/Lc_size/Lheader_v/Lu_size/Lblocks', $data)
    fwrite($this->wp, pack('LLLLL', $this->header['header_size'],$this->header['c_size'],$this->header['header_v'],$this->header['u_size'],$this->header['blocks']));
    
    PHP:
    that works, the following doesn't

    $this->header = unpack('Lheader_size/Lc_size/Lheader_v/Lu_size/Lblocks', $data)
    		fwrite($this->wp, pack('L',$this->header['header_size']));
    		fwrite($this->wp, pack('L',$this->header['c_size']));
    		fwrite($this->wp, pack('L',$this->header['header_v]']));
    		fwrite($this->wp, pack('L',$this->header['u_size']));
    		fwrite($this->wp, pack('L',$this->header['blocks']));
    PHP:
     
    forelmashi, Dec 31, 2007 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    Did you catch your syntax error yet ?
     
    joebert, Dec 31, 2007 IP
  3. forelmashi

    forelmashi Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    there's no syntax error, im playing with a warcraft 3 replay file(it records a played game). warcraft will play the file packed the 1st way, but not the 2nd.

    also interestingly, i can't see the difference in the file (although there must be one). i tried going through each character and looking at it with dechex(ord($thecharacter)) and the 2 versions look identical
     
    forelmashi, Dec 31, 2007 IP
  4. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #4
    How about now, do you see your syntax error yet ?
     
    joebert, Dec 31, 2007 IP
  5. forelmashi

    forelmashi Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    k in my original post it's missing some semicolons.. but they're there in my file.... if that's what you're talking about. it was a rough copy-paste i left out some irrelevant stuff
     
    forelmashi, Dec 31, 2007 IP
  6. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #6
    This line doesn't look a little funny to you ?
     fwrite($this->wp, pack('L',$this->header['header_v]']));
    PHP:
     
    joebert, Dec 31, 2007 IP
  7. forelmashi

    forelmashi Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    lol what do you know, that fixed it. thanks

    the funny thing is i still had to look at that line for 5 minutes thinking "i dont see what's wrong with it"
     
    forelmashi, Dec 31, 2007 IP