PHP 创建标签云函数代码
程序员文章站
2022-04-19 09:25:32
复制代码 代码如下: function getcloud( $data = array(), $minfontsize = 12, $maxfontsize = 30 )...
复制代码 代码如下:
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[] = '<a style="font-size: ' . floor( $size ) . 'px'
. '" href="#" title="\'' . $tag .
'\' returned a count of ' . $count . '">'
. htmlspecialchars( stripslashes( $tag ) ) . '</a>';
}
return join( "\n", $cloudtags ) . "\n";
}
/**************************
**** sample usage ***/
$arr = array('actionscript' => 35, 'adobe' => 22, 'array' => 44, 'background' => 43,
'blur' => 18, 'canvas' => 33, 'class' => 15, 'color palette' => 11, 'crop' => 42,
'delimiter' => 13, 'depth' => 34, 'design' => 8, 'encode' => 12, 'encryption' => 30,
'extract' => 28, 'filters' => 42);
echo getcloud($arr, 12, 36);
这里是摘自之前发布的文章。更多的技巧可以参考。
收集的二十一个实用便利的php函数代码