问题描述:

I want to use PHP's SHA1 function to generate a list of hash/Base64 outputs from a single string.

For example, if I have a string, "ABCDE"

Then I want to generate 5 outputs like:

echo sha1('ABCDE');

echo sha1('BCDE');

echo sha1('CDE');

echo sha1('DE');

echo sha1('E');

And the number of outputs will match the length of the string. How would I accomplish this?

网友答案:
<?php
$s = 'ABCDE';
$t = strlen($s);
for ($i = 1; $i <= $t; $i++) {
  echo sha1($s);
  echo '</br>';
  $s = substr($s, 1);
}
?>

I use a for loop but you can use while too. I don't know how to.

网友答案:

It was annoying me, this is the easiest by far.

$str = 'ABCDE';
while (strlen($str)) {
    echo sha1($str);
    $str = substr($str, 1);
}
相关阅读:
Top