<?php
header("content-type:text/html;charset=utf-8");
/**
*编码
*@param string $string
*/
function urlsafe_b64encode($string){
$data = base64_encode($string);
$data = str_replace(array('+','/'),array('-','_',''),$data);
var_dump($data).'<br/>';
return $data;
}
$a = url_safe_b64encode('请你不要再迷恋哥');
var_dump($a);
echo '<br/>';
/**
*base64解码url
*@param string $string
*@return 如果传的值是一个没有编码的字符串,则返回空
*/
function urlsafe_b64decode(string){
$data = str_replace(array('-','_'),array('+','/'),$string);
$mod4 = strlen($data)%4;
if($mod4){
$data.=substr('===',$mod4);
}
return base64_decode($data);
}
$a = urlsafe_b64decode($a);
var_dump($a);