PHP 创建标签云函数代码

yipeiwu_com6年前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[] = '<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);

这里是摘自【宜配屋www.yipeiwu.com】之前发布的文章。更多的技巧可以参考。
收集的二十一个实用便利的PHP函数代码

相关文章

PHP 图像尺寸调整代码

复制代码 代码如下: /********************** *@filename - path to the image *@tmpname - temporary path...

PHP实现简单搜歌的方法

本文实例讲述了PHP实现简单搜歌的方法。分享给大家供大家参考。具体实现方法如下: <form name="" method="post" action=""> <i...

php设计模式之简单工厂模式详解

php设计模式之简单工厂模式详解

本文以实例形式较为详细的介绍了PHP设计模式的简单工厂模式,对于进行PHP程序设计来说有很好的借鉴作用。具体如下: 一、概念 简单工厂模式 【静态工厂方法模式】(Static Facto...

PHP实现求连续子数组最大和问题2种解决方法

本文实例讲述了PHP实现求连续子数组最大和问题2种解决方法。分享给大家供大家参考,具体如下: 问题描述 求子数组的最大和 题目描述: 输入一个整形数组,数组里有正数也有负数。 数组中连续...

php获取当前月与上个月月初及月末时间戳的方法

本文实例讲述了php获取当前月与上个月月初及月末时间戳的方法。分享给大家供大家参考,具体如下: 当前月 <?php $thismonth = date('m'); $t...