PHP Imitation QQ level solar display function

Source: Internet
Author: User
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>';
?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.