zoukankan      html  css  js  c++  java
  • 简单的标签云实现

    实现代码:

    function _cloudHtml($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="tag.php?name=' . rawurlencode($tag) . '"'
                    . ' title="' . $tag . ' (' . $count . ')">'
                    . htmlspecialchars(stripslashes( $tag)) . '</a>';
        }
        return join( "\n", $cloudTags ) . "\n";
    }

    调用代码:

    function _tagCloud()
    {
        $sql = "select tag, count(1) as count from tbs_tags group by tag";
        $rows = $this->db->getAll($sql);
        foreach ($rows as $row)
        {
            $tags[$row['tag']] = $row['count'];        
        }
        return $this->_cloudHtml($tags, 12, 24);
    }
  • 相关阅读:
    [栈]
    [数据结构实验]学生成绩管理
    [数据结构实验]集合交并
    shapefile 转 geojson 文件类型
    ubuntu sublime text key
    opengl
    c++
    sublime text3 key
    ubuntu安装nvidia驱动
    全球国家svg边界svg
  • 原文地址:https://www.cnblogs.com/eastson/p/2796328.html
Copyright © 2011-2022 走看看