Home > Article > Backend Development > PHP string conversion skills
This article mainly introduces PHP string conversion skills. Interested friends can refer to it. I hope it will be helpful to everyone.
The example of this article describes the QQ space g_tk encryption algorithm implemented by PHP, as follows:
//G_tk计算 function getGTK($skey){ $hash = 5381; for($i=0;$i<strlen($skey);++$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; } }
Summary: The above is the entire content of this article, I hope it can be helpful to everyone learning helps.
Related recommendations:
php implements number formatting, a function that adds commas to every three digits of a number
PHP Mysql jQuery counts the current number of online users
PHP Mysql jQuery implementation of query and list box selection
The above is the detailed content of PHP string conversion skills. For more information, please follow other related articles on the PHP Chinese website!