PDA

Просмотр полной версии : Python -> PHP


Solker
28.06.2009, 04:50
file_hash = md5.md5(base64.encodestring(file_data).replace('\n ','')[:1024]).hexdigest()

Переведите строку пожалуйста из Python на PHP.

Пробовал такой вариант, но MD5 отличаются.


$test = file_get_contents('test.png');
$test = str_replace("\n",'',$test);
$test = base64_encode($test);
echo md5($test);

LEE_ROY
28.06.2009, 05:09
hexdigest() потерял
>>md5.hexdigest()¶
Like digest() except the digest is returned as a string of length 32, containing only hexadecimal digits. This may be used to exchange the value safely in email or other non-binary environments.

Solker
28.06.2009, 05:26
Спасибо конечно, но прикол оказался в этой штуке [:1024]
Оказывается это substr на Питоне.


$test = file_get_contents('test.png');
$test = base64_encode($test);
$test = substr($test,0,1024);
echo md5($test);