Detailed explanation of php base64 encoding and decoding examples

墨辰丷
Release: 2023-03-27 20:08:01
Original
3318 people have browsed it

This article mainly introduces relevant information about php base64 encoding and decoding example codes. Friends in need can refer to

php base64 encoding and decoding detailed explanation

1. Custom rule encoding and decoding

Example


##

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; }
Copy after login


2. Use system functions to complete base64-bit encoding and decoding

Example 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); }
Copy after login


The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

php implements reading and savingbase64encoded image content

JS implements 3desbase64Detailed explanation of encryption and decryption algorithm steps

H5 mobile development Ajax uploads multiple Base64 format pictures to server

The above is the detailed content of Detailed explanation of php base64 encoding and decoding examples. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!