PHP function unpack

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux