Home > php教程 > php手册 > body text

php仿QQ等级太阳显示函数

WBOY
Release: 2016-06-21 09:07:37
Original
1219 people have browsed it

开头先引述下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="images/time_star.gif" alt="php仿QQ等级太阳显示函数" >';<br>$tImage2 = '<img src="images/time_yueliang.gif" alt="php仿QQ等级太阳显示函数" >';<br>$tImage3 = '<img src="images/time_sun.gif" 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>?>



Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template