Rumah > php教程 > php手册 > php仿QQ等级太阳显示函数

php仿QQ等级太阳显示函数

WBOY
Lepaskan: 2016-06-21 09:07:37
asal
1247 orang telah melayarinya

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



Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan