首页  >  文章  >  php教程  >  PHP创建标签云

PHP创建标签云

PHP中文网
PHP中文网原创
2016-05-25 17:11:561000浏览

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);
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn