有人可以告诉我如何将这个函数重写为 MySQL 函数以便能够直接在 MySQL 上进行解码吗?
const CHAR_MAP = 'abcdefghijklmnopqrstuvwxz0123456789';
function decode($encoded) {
$elen = strlen($encoded);
$cmlen = strlen(Mobile::CHAR_MAP);
$offset = strpos(Mobile::CHAR_MAP, substr($encoded, 0, 1), 1);
$decoded = '';
$check = 0;
for ($i=1;$i<$elen-1;$i++) {
$a = strpos(Mobile::CHAR_MAP, substr($encoded, $i, 1), 1);
$x = $a - $offset * $i;
$x %= $cmlen;
if ($x < 0) {
$x = $cmlen + $x;
}
$decoded .= $x;
$check += $x;
}
return $decoded;
}