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

PHP创建标签云

PHP中文网
發布: 2016-05-25 17:11:56
原創
1026 人瀏覽過

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
作者最新文章
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板