Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl中md5函数的PHP类似物是什么?_Php_Perl - Fatal编程技术网

Perl中md5函数的PHP类似物是什么?

Perl中md5函数的PHP类似物是什么?,php,perl,Php,Perl,我有一个Perl脚本,需要将其转换为PHP。 Perl中的md5函数的PHP类似物是什么 Perl脚本: $hash = md5($str1, $str2); PHP脚本: $hash = md5($str1.$str2); 我在$hash中有不同的值。 如何在PHP中获得相同的$hash值 Thx.看起来像您正在使用的二进制格式输出的perl版本: 此函数将连接所有参数,计算MD5摘要 并以二进制形式返回它。返回的字符串 将有16个字节长 在PHP中尝试以下操作: $hash

我有一个Perl脚本,需要将其转换为PHP。 Perl中的
md5
函数的PHP类似物是什么

Perl脚本:

$hash  = md5($str1, $str2); 
PHP脚本:

 $hash  = md5($str1.$str2);
我在
$hash
中有不同的值。 如何在PHP中获得相同的
$hash


Thx.

看起来像您正在使用的二进制格式输出的perl版本:

此函数将连接所有参数,计算MD5摘要 并以二进制形式返回它。返回的字符串 将有16个字节长

在PHP中尝试以下操作:

$hash  = md5($str1.$str2, true);
有关详细信息,请参阅php。

它很简单

$hash  = md5($str1.$str2, true);
您声称它不是等效的,但以下内容表明它是等效的:

$ cat x.pl
use Digest::MD5 qw( md5 );

my $str1 = join '', map chr, 0x00..0x7F;
my $str2 = join '', map chr, 0x80..0xFF;

print md5($str1, $str2);

$ perl x.pl | od -t x1
0000000 e2 c8 65 db 41 62 be d9 63 bf aa 9e f6 ac 18 f0
0000020

$cat x.php
$php x.php | od-t x1
0000000 e2 c8 65 db 41 62 be d9 63 bf aa 9e f6 ac 18 f0
0000020


$diff-q请看这里,在进行哈希之前确保字符串实际上是相同的是的,输入数据是不同的。这是正确的Perl代码吗?似乎您正在使用
add
方法?
$ cat x.pl
use Digest::MD5 qw( md5 );

my $str1 = join '', map chr, 0x00..0x7F;
my $str2 = join '', map chr, 0x80..0xFF;

print md5($str1, $str2);

$ perl x.pl | od -t x1
0000000 e2 c8 65 db 41 62 be d9 63 bf aa 9e f6 ac 18 f0
0000020
$ cat x.php
<?php

$str1 = join('', array_map("chr", range(0x00, 0x7F)));
$str2 = join('', array_map("chr", range(0x80, 0xFF)));

echo md5($str1.$str2, true);

?>

$ php x.php | od -t x1
0000000 e2 c8 65 db 41 62 be d9 63 bf aa 9e f6 ac 18 f0
0000020
$ diff -q <( perl x.pl ) <( php x.php ) && echo identical || echo different
identical