Describes the sample code of phpbase64 encoding and decoding in detail.

Source: Internet
Author: User
This article mainly introduces the relevant information about the php base64 encoding and decoding instance code. For more information, see the following article, for more information, see

Php base64 encoding and decoding

1. encoding and decoding using custom rules

Instance

 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. complete base64 encoding and decoding using system functions

Instance code:

 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);      }

The above section details the sample code for php base64 encoding and decoding. For more information, see other related articles in the first PHP community!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.