If you use the base64_encode and base64_decode methods directly, the generated string may not be suitable for URL addresses. The following methods can solve this problem:
URL safe string encoding:
Copy code The code is as follows:
function urlsafe_b64encode($string) {
$data = base64_encode($string);
$data = str_replace(array('+','/','='),array('-','_',''),$data);
Return $data;
}
URL-safe string decoding:
Copy code The code is as follows:
function urlsafe_b64decode($string) {
$data = str_replace(array('-','_'),array('+','/'),$string);
$mod4 = strlen($data) % 4;
if ($mod4) {
$data .= substr('====', $mod4);
}
Return base64_decode($data);
}
http://www.bkjia.com/PHPjc/825408.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825408.htmlTechArticleIf you use the base64_encode and base64_decode methods directly, the generated string may not be suitable for the URL address. The following method can solve this problem: URL-safe string encoding: Copy...
Statement: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