快捷搜索: 王者荣耀 脱发

php base64编码地址栏含有下划线解决

php传递参数如果是一个url,就需要转化下传输,使用php的bs64编码来进行编码,发现编码后的数据带有下划线,浏览器不识别

只能进行转化改版bs64转码解码方法 。

首先我们看下bs64的编码方法

static const char base64_table[] = { 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, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +, /, };只有这些字符进行处理编码.我们把/和+做下处理

if (!function_exists(urlSafeB64encode)) { function urlSafeB64encode($string) { $data = base64_encode($string); $data = str_replace(array(+, /, =), array(-, _, ), $data); return $data; } }

if (!function_exists(urlSafeB64decode)) { function urlSafeB64decode($string) { $data = str_replace(array(-,_),array(+,/),$string); $mod4 = strlen($data) % 4; if ($mod4) { $data .= substr(====, $mod4); } return base64_decode($data); } }

经验分享 程序员 微信小程序 职场和发展