开头先引述下QQ等级的算法:
设当前等级为N,达到当前等级最少需要的活跃天数为D,当前活跃天数为Dc,升级剩余天数为Dr,则:
从而推出:
好了,引述完成,懒得写字了,贴出代码:
复制内容到剪贴板
代码:
<?php <br/>/**<br>*<br>* QQ等级输出类库<br>* @author 毛毛虫 <wangchong1985><br>* @version 1.0 2008-04-09<br>* <br>*/<br>class showRank {<br> <br> /**<br> * 第一级图片显示字段<br> */<br> public $mImage1;<br> <br> /**<br> * 第二级图片显示字段<br> */<br> public $mImage2;<br> <br> /**<br> * 第三级图片显示字段<br> */<br> public $mImage3;<br> /**<br> * 构造函数:传入图片值<br> * @return 无<br> */<br> function __construct($pImage1 = '★',$pImage2 = '▲',$pImage3 = '●') {<br> $this->mImage1 = $pImage1;<br> $this->mImage2 = $pImage2;<br> $this->mImage3 = $pImage3;<br> }<br> <br> /**<br> * 根据活跃天数计算用户等级。(模仿QQ的升级方式)<br> * @return int<br> * @access public<br> */<br> function get_rank($pScore) {<br> $temp = $pScore+4;<br> $tRank = sqrt($temp)-2;<br> $tRank = floor($tRank);<br> return $tRank;<br> }<br> <br> /**<br> * 用户等级标志,根据用户等级显示用户标志<br> * 仿照QQ等级的四进制显示<br> * @return str<br> * @access public<br> */<br> function get_score($pScore) {<br> $str = '';<br> $tRank = $this->get_rank($pScore);//根据分数取得等级<br> $tPicNum = base_convert($tRank,10,4);//转化为四进制<br> $tPicNum = strrev($tPicNum);//翻转字符串<br> $tArray = str_split($tPicNum);//转化为数组<br> $tNum = count($tArray);<br> if($tNum for($i=$tNum-1;$i>=0;$i--){<br> switch($i){<br> case '0':<br> for($j=0;$j $str .= $this->mImage1;<br> }<br> break;<br> case '1':<br> for($j=0;$j $str .= $this->mImage2;<br> }<br> break;<br> case '2':<br> for($j=0;$j $str .= $this->mImage3;<br> }<br> break;<br> default:<br> //$str = ;<br> break;<br> }<br> }<br> }else {<br> $str = $this->mImage3.$this->mImage3.$this->mImage3.$this->mImage3;<br> }<br> return $str;<br> }<br>}<br>?></wangchong1985>
以上就是显示类,再来个简单的调用实例:
复制内容到剪贴板
代码:
<?php <br/>require_once('showRank.php');<br>//定义等级图片<br>$tImage1 = '<img src="/static/imghwm/default1.png" data-src="images/time_star.gif" class="lazy" alt="php仿QQ等级太阳显示函数" >';<br>$tImage2 = '<img src="/static/imghwm/default1.png" data-src="images/time_yueliang.gif" class="lazy" alt="php仿QQ等级太阳显示函数" >';<br>$tImage3 = '<img src="/static/imghwm/default1.png" data-src="images/time_sun.gif" class="lazy" alt="php仿QQ等级太阳显示函数" >';<br>//实例化并传输等级图片<br>$tShow = new showRank($tImage1,$tImage2,$tImage3);<br>//输入的活跃天数<br>$tScore = 1009;<br>$echo = $tShow->get_score($tScore);<br>//输出显示效果<br>print '<div align="center">'.$echo.'</div>';<br>?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks agoByDDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks agoByDDD
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use