欢迎访问 水平网    今天是:2017年11月19日 注册 | 登录 | 订阅 | 收藏
>> PHP >> PHP创建标签云
推荐代码
热点代码

PHP创建标签云

作者:未知,  来源:网络,  阅读:1513,  发布时间:2014-06-29  【放入收藏夹
代码:PHP复制
function getCloud( $data = array(), $minFontSize = 12, $maxFontSize = 30 )
{
    $minimumCount = min( array_values( $data ) );
    $maximumCount = max( array_values( $data ) );
    $spread       = $maximumCount - $minimumCount;
    $cloudHTML    = '';
    $cloudTags    = array(); 

    $spread == 0 && $spread = 1; 

    foreach( $data as $tag => $count )
    {
        $size = $minFontSize + ( $count - $minimumCount )
            * ( $maxFontSize - $minFontSize ) / $spread;
        $cloudTags[] = '<a style="font-size: ' . floor( $size ) . 'px'
        . '" href="#" title="\'' . $tag  .
        '\' returned a count of ' . $count . '">'
        . htmlspecialchars( stripslashes( $tag ) ) . '</a>';
    } 

    return join( "\n", $cloudTags ) . "\n";
}
/**************************
****   Sample usage    ***/
$arr = Array('Actionscript' => 35, 'Adobe' => 22, 'Array' => 44, 'Background' => 43,
    'Blur' => 18, 'Canvas' => 33, 'Class' => 15, 'Color Palette' => 11, 'Crop' => 42,
    'Delimiter' => 13, 'Depth' => 34, 'Design' => 8, 'Encode' => 12, 'Encryption' => 30,
    'Extract' => 28, 'Filters' => 42);
echo getCloud($arr, 12, 36);
Tags:标签
评论【共有0条评论】查看所有评论
昵称:(*)   邮箱:   QQ:   验证码: 看不清楚?点击刷新验证码