将 Perl 函数转换为 PHP

发布于 2024-09-09 02:19:36 字数 404 浏览 9 评论 0原文

我想将下面的 perl 函数转换为 PHP 函数,如果有人可以提供一点帮助,我将不胜感激:

sub encode32
{
    $_=shift;
    my($l,$e);
    $_=unpack('B*',$_);
    s/(.....)/000$1/g;
    $l=length;
    if($l & 7)
    {
        $e=substr($_,$l & ~7);
        $_=substr($_,0,$l & ~7);
        $_.="000$e" . '0' x (5-length $e);
    }
    $_=pack('B*', $_);
    tr|\0-\37|A-Z2-7|;
    lc($_);
}

提前致谢。

I want to convert the perl function below to PHP function, if someone could help a little bit I'd appreaciate it:

sub encode32
{
    $_=shift;
    my($l,$e);
    $_=unpack('B*',$_);
    s/(.....)/000$1/g;
    $l=length;
    if($l & 7)
    {
        $e=substr($_,$l & ~7);
        $_=substr($_,0,$l & ~7);
        $_.="000$e" . '0' x (5-length $e);
    }
    $_=pack('B*', $_);
    tr|\0-\37|A-Z2-7|;
    lc($_);
}

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请爱~陌生人 2024-09-16 02:19:36

它是 RFC 3548 的 Base32 编码的本地实现。根据 GPL 条款分发的 PHP 实现可在 Fremnet 上找到。

使用示例:

<?
include('class.base32.php5');

function encode32($str) {
  $b = new Base32(Base32::csRFC3548);
  return strtolower($b->fromString($str));
}

print encode32("foo bar baz quux") . "\n";
?>

输出:

mzxw6idcmfzcaytbpiqhc5lvpa

It's a homegrown implementation of the Base32 encoding from RFC 3548. A PHP implementation distributed under the terms of the GPL is available at Fremnet.

Example use:

<?
include('class.base32.php5');

function encode32($str) {
  $b = new Base32(Base32::csRFC3548);
  return strtolower($b->fromString($str));
}

print encode32("foo bar baz quux") . "\n";
?>

Output:

mzxw6idcmfzcaytbpiqhc5lvpa
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文