PHP function unpack

From: Date: Sun, 11 Oct 2009 14:42:01 +0000
Subject: PHP function unpack
Groups: php.general 
Request: Send a blank email to php-general+get-298835@lists.php.net to get a copy of this message
Hi, I'm new to the list and I've search internet and didn't find an answer to my problem. I'm converting a perl script to PHP and I've done almost everything. The only part of the code that I didn't get working on PHP was: (PERL CODE) foreach ($b_length,$b_mac,$b_crlf,$b_crlf,$a_body) { $d_checksum += unpack("%16n*", $_); } The idea is to make a 16-bit checksum of all elements ($b_length,$b_mac,$b_crlf,$b_crlf,$a_body). I'm tried translating the code to: $arr_checksum = array($b_length,$b_mac,$b_crlf,$b_crlf,$File_Content); $d_checksum = 0; foreach($arr_checksum as $check_elem){ $d_check = unpack("n*", $check_elem); for ($i=0;$i<4;$i++){ $d_checksum += $d_check["$i"]; } } But the result is different. I know that unpack in perl and php are different, but I cant find a way to translate the format %16n* of perl to php and generate a 16-bit checksum. Any help will be appreciated. []'s Gabriel.

« previous php.general (#298835) next »