Home > php教程 > php手册 > body text

URL安全的字符串base64编码和解码

WBOY
Release: 2016-06-07 11:45:53
Original
1648 people have browsed it

如果直接使用base64_encode和base64_decode方法的话,生成的字符串可能不适用URL地址。下面的方法可以解决该问题:
URL安全的字符串编码:function urlsafe_b64encode($string) {<br>    $data = base64_encode($string);<br>    $data = str_replace(array('+','/','='),array('-','_',''),$data);<br>    return $data;<br> }URL安全的字符串解码:function urlsafe_b64decode($string) {<br>    $data = str_replace(array('-','_'),array('+','/'),$string);<br>    $mod4 = strlen($data) % 4;<br>    if ($mod4) {<br>        $data .= substr('====', $mod4);<br>    }<br>    return base64_decode($data);<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

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
Popular Recommendations
Popular Tutorials
More>
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!