/** * 生成特征值 * @param $url $subdomain.$maindomain.$path.$readid */ function InitFeature($url) { $md5Url = md5($url); $this->md5Url = $md5Url; $this->arrFeature = str_split(toTen(substr($md5Url, 0, 8)) . toTen(substr($md5Url, 8, 8)) . toTen(substr($md5Url, 16, 8)) . toTen(substr($md5Url, 24, 8)), 1); $arrLibFeature = array(); for ($i = 0; $i < 7; $i++) { $arrLibFeature[$i] = ToTen(substr($md5Url, $i * 4, 4)) + 1; $arrLibFeature[$i + 7] = ToTen(substr($md5Url, $i * 4 + 1, 4)) + 1; $arrLibFeature[$i + 14] = ToTen(substr($md5Url, $i * 4 + 2, 4)) + 1; $arrLibFeature[$i + 21] = ToTen(substr($md5Url, $i * 4 + 3, 4)) + 1; } $this->arrLibFeature = $arrLibFeature; }
/** * 16进制转36进制 * @param $num * @param $start_no * @param $len * @return string */ function Md5To36($num, $start_no, $len) { $arrTrans = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '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'); $tenNo = ToTen(substr($num, $start_no, $len)); $resultNo = ''; do { $a = ceil($tenNo / 36); $b = fmod(floatval($tenNo), 36); $tenNo = $a; $resultNo = $arrTrans[$b] . $resultNo; } while ($tenNo >= 36); $resultNo = $arrTrans[$tenNo] . $resultNo; return $resultNo; }