Skip to content

Instantly share code, notes, and snippets.

@noscripter
Forked from hisway/weibo-pic.php
Created June 23, 2018 03:10
Show Gist options
  • Save noscripter/da645bc6a3b7384920a24dac5103bc84 to your computer and use it in GitHub Desktop.
Save noscripter/da645bc6a3b7384920a24dac5103bc84 to your computer and use it in GitHub Desktop.
function from62to10($num) {
$from = 62;
$num = strval($num);
$dict = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$len = strlen($num);
$dec = 0;
for($i = 0; $i < $len; $i++) {
$pos = strpos($dict, $num[$i]);
$dec = bcadd(bcmul(bcpow($from, $len - $i - 1), $pos), $dec);
}
return $dec;
}
function decode($url) {
$file = basename($url,'.jpg');
$code = substr($file, 0, 8);
if (substr($code, 0, 2) == '00') {
return from62to10($code);
} else {
return hexdec($code);
}
}
$weibo = 'http://weibo.com/u/' . decode($url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment