本文介绍了如何为base64转换为base10在PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前转换base10编号为base64在PHP。但我没有任何想法base64转换为base10在PHP!

我该怎么办呢?

我的算法转换base10为Base64:

  $代表= array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','_');
$新=;
而($ num个> 0){
    $ R = $ NUM%64;
    。$新= $代表[$ R]。
    $ NUM =地板($ NUM / 64);
}
 

解决方案

下面是做这件事的一个Javascript的方式。也许你可以code一为PHP。

变种。字母= {' - '62',1':53,0:52,'3':55,'2':54,5: 57,'4':56,'7':59,'6':58,'9'61'8'60,A:0,C:2,B:1, E:4,D:3,G:6,F:5,'I':8',H':7,K:10,J:9,M ':12,L:11,O:14,N:13,Q:16,P:15,S:18,R:17,U​​: 20,T:19,W:22,V:21,Y:24,X:23,Z:25,_63,一:26, C:28,B:27,E:30,D:29,G:32,F:31,我:34,H:33,数k ':36,J:35,M:38,L:37,O:40,N:39,Q:42,P:41,S: 44,R:43,U:46,T:45,W:48,V:47,Y:50,X:49,Z:51} ;

功能去code(S){
    变种N = 0;
    对于(VAR I = 0; I< s.length;我++){
        变种C = s.charAt(我);
        N = N * 64 + ALPHABET [C]。
    }
    返回N;
}

的console.log(德code('EqfyK'));
 

I currently convert base10 numbers to base64 in PHP.but I haven't any idea for convert base64 to base10 in php!

How can I do it?

my algorithm for convert base10 to base64:

$rep = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','_');
$new = "";
while ($num>0) {
    $r = $num % 64;
    $new .= $rep[$r];
    $num = floor($num/64);
}
解决方案

Here is a Javascript way of doing it. Perhaps you can code one for php.

var ALPHABET = {'-': 62, '1': 53, '0': 52, '3': 55, '2': 54, '5': 57, '4': 56, '7': 59, '6': 58, '9': 61, '8': 60, 'A': 0, 'C': 2, 'B': 1, 'E': 4, 'D': 3, 'G': 6, 'F': 5, 'I': 8, 'H': 7, 'K': 10, 'J': 9, 'M': 12, 'L': 11, 'O': 14, 'N': 13, 'Q': 16, 'P': 15, 'S': 18, 'R': 17, 'U': 20, 'T': 19, 'W': 22, 'V': 21, 'Y': 24, 'X': 23, 'Z': 25, '_': 63, 'a': 26, 'c': 28, 'b': 27, 'e': 30, 'd': 29, 'g': 32, 'f': 31, 'i': 34, 'h': 33, 'k': 36, 'j': 35, 'm': 38, 'l': 37, 'o': 40, 'n': 39, 'q': 42, 'p': 41, 's': 44, 'r': 43, 'u': 46, 't': 45, 'w': 48, 'v': 47, 'y': 50, 'x': 49, 'z': 51};

function decode(s) {
    var n = 0;
    for(var i=0; i < s.length; i++) {
        var c = s.charAt(i);
        n = n * 64 + ALPHABET[c];
    }
    return n;
}

console.log(decode('EqfyK'));

这篇关于如何为base64转换为base10在PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:05