首頁  >  文章  >  php教程  >  php仿QQ等级太阳显示函数

php仿QQ等级太阳显示函数

WBOY
WBOY原創
2016-06-21 09:07:371210瀏覽

开头先引述下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>?>



陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn