urlensafe: function (str) {
var data = window.btoa(str);
data = data.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g,'')
return data;
},
encode: function (str) {
var m = parseInt(Math.random() * 35 + 1)*7
var n = String.fromCharCode(m)
var a = n
var tmp = ''
for (var i = 0; i < str.length; i += 2) {
n = a.charCodeAt(0) ^ str.charCodeAt(i)
tmp += String.fromCharCode(n)
if (i + 1 < str.length) {
n = n ^ str.charCodeAt(i + 1)
tmp += String.fromCharCode(n)
}
}
tmp = a + tmp
return this.urlensafe(tmp);
},
第1个回答 2019-04-10
//对应js的Math.random,引用网址:https://www.cnblogs.com/haciont/p/6224953.html
function random($min = 0, $max = 1){
return $min + mt_rand()/mt_getrandmax()*($max-$min);
}
function urlensafe ($str){
$data = base64_encode($str);
return str_replace(['+','/','='],['-','_',''],$data);
}
function encode($str){
$m=(int)(random() * 35 + 1)*7;
$a=$n=chr($m);
$tmp='';
$len=mb_strlen($str,'utf-8');//strlen($str);
for ($i = 0; $i < $len; $i += 2) {
$n = ord($a[0]) ^ ord($str[$i]);
$tmp .= chr($n);
if ($i + 1 < $len) {
$n = $n ^ ord($str[$i+1]);
$tmp .= chr($n);
}
}
$tmp = $a.$tmp;
return urlensafe($tmp);
}本回答被网友采纳
function random($min = 0, $max = 1){
return $min + mt_rand()/mt_getrandmax()*($max-$min);
}
function urlensafe ($str){
$data = base64_encode($str);
return str_replace(['+','/','='],['-','_',''],$data);
}
function encode($str){
$m=(int)(random() * 35 + 1)*7;
$a=$n=chr($m);
$tmp='';
$len=mb_strlen($str,'utf-8');//strlen($str);
for ($i = 0; $i < $len; $i += 2) {
$n = ord($a[0]) ^ ord($str[$i]);
$tmp .= chr($n);
if ($i + 1 < $len) {
$n = $n ^ ord($str[$i+1]);
$tmp .= chr($n);
}
}
$tmp = $a.$tmp;
return urlensafe($tmp);
}本回答被网友采纳
第2个回答 2019-04-10
js是前台脚本 也就是在客户端运行的,php是后台脚本,在服务器运行的 ,互相不能转换的!追问
有大神能转换的