First quote the next QQ level algorithm:
Set the current level to n, the minimum number of active days to reach the current level is D, current active days are DC, and the number of days to upgrade is DR:
Thereby introducing:
Okay, quote finished, lazy to write, post code: copy content to clipboard
Code:
<?php
/**
*
* QQ Grade Output Class Library
* @author Caterpillar <wangchong1985@gmail.com>
* @version 1.0 2008-04-09
*
*/
Class Showrank {
/**
* First level picture display field
*/
Public $mImage 1;
/**
* Second-level picture display field
*/
Public $mImage 2;
/**
* Third-level picture display field
*/
Public $mImage 3;
/**
* Constructor: Incoming picture value
* @return No
*/
function __construct ($pImage 1 = ' ★ ', $pImage 2 = ' ▲ ', $pImage 3 = ') {
$this->mimage1 = $pImage 1;
$this->mimage2 = $pImage 2;
$this->mimage3 = $pImage 3;
}
/**
* Calculate the user level based on active days. (Imitate QQ upgrade way)
* @return int
* @access Public
*/
function Get_rank ($pScore) {
$temp = $pScore +4;
$tRank = sqrt ($temp)-2;
$tRank = Floor ($tRank);
return $tRank;
}
/**
* User level flag, display user logo according to user level
* Imitate the QQ level of the four-system display
* @return Str
* @access Public
*/
function Get_score ($pScore) {
$str = ';
$tRank = $this->get_rank ($pScore)//Grade by score
$tPicNum = Base_convert ($tRank, 10,4);//Convert to four
$tPicNum = Strrev ($tPicNum);//Flip string
$tArray = Str_split ($tPicNum);//convert to an array
$tNum = count ($tArray);
if ($tNum <=3) {
for ($i = $tNum-1; $i >=0; $i-) {
Switch ($i) {
Case ' 0 ':
for ($j =0; $j < $tArray [$i]; $j + +) {
$str. = $this->mimage1;
}
Break
Case ' 1 ':
for ($j =0; $j < $tArray [$i]; $j + +) {
$str. = $this->mimage2;
}
Break
Case ' 2 ':
for ($j =0; $j < $tArray [$i]; $j + +) {
$str. = $this->mimage3;
}
Break
Default
$STR =;
Break
}
}
}else {
$str = $this->mimage3. $this->mimage3. $this->mimage3. $this->mimage3;
}
return $str;
}
}
?>
The above is the display class, and then a simple invocation instance: Copy content to clipboard
Code:
<?php
require_once('showRank.php');
//定义等级图片
$tImage1 = '';
$tImage2 = '';
$tImage3 = '';
//实例化并传输等级图片
$tShow = new showRank($tImage1,$tImage2,$tImage3);
//输入的活跃天数
$tScore = 1009;
$echo = $tShow->get_score($tScore);
//输出显示效果
print '<div align=center>'.$echo.'</div>';
?>