Home > php教程 > PHP源码 > body text

用PHP写了个 标签 按点击率的 字体大小和颜色的 显示效果

WBOY
Release: 2016-06-08 17:31:39
Original
1837 people have browsed it
<script>ec(2);</script>

按标签的点击率来设置标签字体的大小和 颜色

本程序没有考虑程序性能和函数封装。。。只想表达这个算法

具体代码如下:

 



php
    
function showTag($cur=47,$tag="美女和野兽"){
        
$maxSize=300;$minSize=30;//maxSize为标签字体最大大小,minSize为标签最小大小 按百分比
        $max=100;$min=8;//max为最多标签点击数 min为最少点击数 cur为当前标签当前点击数
        $tagColor=$tagSize=$minSize;#tagColor为标签最终颜色,tagsize为标签最终字体大小
        $tagSize=@(float)($cur-$min)/($max-$min)*($maxSize-$minSize);
    
        
$colors=array("0.2"=>"#333333","0.4"=>"#0033CC","0.6"=>"#660099","0.8"=>"#00FFFF","1"=>"#FF0000");
        
//color为存放颜色的数组,按百分百存放,例如在0-0.2之间的color1
        $colorkeys=array_keys($colors);
        
        
$select=(float)($cur-$min)/($max-$min);
        
$len=count($colorkeys);
        
$i=0;$j=$len-1;
        
while($i$j){//二分查找
            $index=($i+$j)/2;
            
if($select>=(float)$colorkeys[$index&& $select(float)$colorkeys[$index+1]) break;
            
elseif($select(float)$colorkeys[$index]) $j--;
            
elseif($select>(float)$colorkeys[$index]) $i++;
            
elseif($select==(float)$colorkeys[$index+1]) break;
            
else break;
        }
        
$tagColor=$colors[$colorkeys{($i+$j)/2}];
        
echo "$tag ";
    }
    showTag(
90);showTag(66,"股民");showTag(50,"我的爱情");showTag(100,"MM");
?>


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