PHP 创建标签云函数代码

2015-01-24信息快讯网

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); 

这里是摘自脚本之家之前发布的文章。更多的技巧可以参考。
收集的二十一个实用便利的PHP函数代码
有关php运算符的知识大全
PHP读取txt文件的内容并赋值给数组的代码
PHP支持多种格式图片上传(支持jpg、png、gif)
PHP安全防范技巧分享
PHP隐形一句话后门,和ThinkPHP框架加密码程序(base64_decode)
php数组函数序列之krsort()- 对数组的元素键名进行降序排序,保持索引关系
php数组函数序列之asort() - 对数组的元素值进行升序排序,保持索引关系
php数组函数序列之sort() 对数组的元素值进行升序排序
php数组函数序列之ksort()对数组的元素键名进行升序排序,保持索引关系
php数组函数序列之rsort() - 对数组的元素值进行降序排序
php中批量修改文件后缀名的函数代码
PHP实现时间轴函数代码
使用PHP遍历文件夹与子目录的函数代码
PHP获取MAC地址的函数代码
PHP url 加密解密函数代码
PHP为表单获取的URL 地址预设 http 字符串函数代码
PHP 强制性文件下载功能的函数代码(任意文件格式)
PHP 图像尺寸调整代码
用PHP将网址字符串转换成超链接(网址或email)
php 编写安全的代码时容易犯的错误小结
Windows7下PHP开发环境安装配置图文方法
PHP array_flip() 删除重复数组元素专用函数
php date()日期时间函数详解
php5.3 废弃函数小结
php 数组操作(增加,删除,查询,排序)等函数说明第1/2页
PHP URL地址获取函数代码(端口等) 推荐
PHP CURL模拟GET及POST函数代码
收集的二十一个实用便利的PHP函数代码
PHP 获取远程文件内容的函数代码
©2014-2024 dbsqp.com