本篇文章主要介绍php针对字符串的转换技巧,感兴趣的朋友参考下,希望对大家有所帮助。
本文实例讲述了PHP实现的QQ空间g_tk加密算法,具体如下://G_tk计算
function getGTK($skey){
$hash = 5381;
for($i=0;$i
$hash += ($hash << 5) + utf8_unicode($skey[$i]);
}
return $hash & 0x7fffffff;
}
function utf8_unicode($c) {
switch(strlen($c)) {
case 1:
return ord($c);
case 2:
$n = (ord($c[0]) & 0x3f) << 6;
$n += ord($c[1]) & 0x3f;
return $n;
case 3:
$n = (ord($c[0]) & 0x1f) << 12;
$n += (ord($c[1]) & 0x3f) << 6;
$n += ord($c[2]) & 0x3f;
return $n;
case 4:
$n = (ord($c[0]) & 0x0f) << 18;
$n += (ord($c[1]) & 0x3f) << 12;
$n += (ord($c[2]) & 0x3f) << 6;
$n += ord($c[3]) & 0x3f;
return $n;
}
}
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
php实现数字格式化,数字每三位加逗号的功能函数
PHP+Mysql+jQuery统计当前在线用户数
PHP+Mysql+jQuery实现的查询和列表框选择