php base64 编码与解码实例代码

yipeiwu_com7年前PHP代码库

php base64 编码与解码详解

1.自定义规则方式编码和解码

实例

 public function test_changinttoStr () {
    $intvalue1 = 1232344234;
    $intStr = '';
    $str = "Y 9 L F k g y 5 R o v i x I 1 a O f 8 U h d s 3 r 4 D M p l Q Z J X P q e b E 0 W S j B n 7 w V z m N 2 G c 6 T H C A K u t";
    $seq = explode(" ", $str);
    $intvalue = $intvalue1;
    while ($intvalue >= 62) {
      # code...
      $intStr = ($seq[$intvalue % 62]).$intStr ;
      $intvalue = (int)($intvalue / 62);
    }
    $intStr = ($seq[$intvalue]).$intStr;
    echo($intStr);
    $keySeq= array_flip($seq);
    $length = strlen($intStr);
    $value = 0;
    for ($i = $length -1; $i >=0; $i--) {
      $t = $keySeq[$intStr[$i]];
        $s = ($length - $i) - 1;
        $m = (pow(62, $s) * $t);
      $value += $m;
    }
    echo $value;
  }

2.利用系统函数完成base64位的编码和解码

实例代码:

 public function testArray(){
//    $str['a'] = 'sdfsdf';
//    $str['d'] = 'sdafsdf';
//    $newStr = $this->modifyArray($str);

    $value = gmp_strval(gmp_init('234234234234',10),62);

    $newValue = gmp_strval(gmp_init($value,62),10);
    
  }


感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

相关文章

PHP 实现页面静态化的几种方法

1、通过buffer来实现 需要用file_put_contents ob_get_clean()等内置函数 ob_start (); include "filterpost.htm...

PHP Warning: Module 'modulename' already loaded in问题解决办法

出现标题这样的错误大概是: 1、模块加载了两次,所以php -i|grep Configure,看一下配置文件和配置include的目录,对于这些文件中是否有同名的module 2、动态...

PHP简单实现二维数组赋值与遍历功能示例

本文实例讲述了PHP简单实现二维数组赋值与遍历功能。分享给大家供大家参考,具体如下: 示例1: <?php $loptop1['lid'] = 1000; $l...

基于PHP5魔术常量与魔术方法的详解

魔术常量:1。__LINE__返回文件中的当前行号。2。__FILE__  返回文件的完整路径和文件名。如果用在包含文件中,则返回包含文件名。自PHP4.0.2 起,__FILE__总是...

PHP输出数组中重名的元素的几种处理方法

1.可以直接用php的内置函数array_intersect() array array_intersect ( array $array1 , array $array2 [, arr...