首页 > php教程 > PHP源码 > PHP创建标签云

PHP创建标签云

PHP中文网
发布: 2016-05-25 17:11:56
原创
1027 人浏览过

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[] = &#39;<a style="font-size: &#39; . floor( $size ) . &#39;px&#39;
. &#39;" href="#" title="\&#39;&#39; . $tag .
&#39;\&#39; returned a count of &#39; . $count . &#39;">&#39;
. htmlspecialchars( stripslashes( $tag ) ) . &#39;</a>&#39;;
} 

return join( "\n", $cloudTags ) . "\n";
}
/**************************
**** Sample usage ***/
$arr = Array(&#39;Actionscript&#39; => 35, &#39;Adobe&#39; => 22, &#39;Array&#39; => 44, &#39;Background&#39; => 43,
&#39;Blur&#39; => 18, &#39;Canvas&#39; => 33, &#39;Class&#39; => 15, &#39;Color Palette&#39; => 11, &#39;Crop&#39; => 42,
&#39;Delimiter&#39; => 13, &#39;Depth&#39; => 34, &#39;Design&#39; => 8, &#39;Encode&#39; => 12, &#39;Encryption&#39; => 30,
&#39;Extract&#39; => 28, &#39;Filters&#39; => 42);
echo getCloud($arr, 12, 36);
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板