Re: PHP function unpack
| From: | Gabriel Hahmann | Date: | Thu, 15 Oct 2009 15:59:01 +0000 |
| Subject: | Re: PHP function unpack | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298899@lists.php.net to get a copy of this message | ||
Hi,
I've sent this mail a few days ago, but as this list have a very high
traffic maybe my mail disappear from you inbox.
Any help would be appreciated.
Thanks in advance,
Gabriel.
On Sun, Oct 11, 2009 at 4:42 PM, Gabriel Hahmann
<gabriel.hahmann@gmail.com> wrote:
> 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.
>