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

PHP创建标签云

PHP中文网
PHP中文网Original
2016-05-25 17:11:561023browse

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);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP代替FTP删目录(待测试)Next article:PHP销毁目录