PHP 标签云
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 标签云相关的知识,希望对你有一定的参考价值。
function printTagCloud($tags) {
// $tags is the array
arsort($tags);
$max_size = 32; // max font size in pixels
$min_size = 12; // min font size in pixels
// largest and smallest array values
$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));
// find the range of values
$spread = $max_qty - $min_qty;
if ($spread == 0) { // we don't want to divide by zero
$spread = 1;
}
// set the font-size increment
$step = ($max_size - $min_size) / ($spread);
// loop through the tag array
foreach ($tags as $key => $value) {
// calculate font-size
// find the $value in excess of $min_qty
// multiply by the font-size increment ($size)
// and add the $min_size set above
$size = round($min_size + (($value - $min_qty) * $step));
echo '<a href="#" style="font-size: ' . $size . 'px" title="' . $value . ' things tagged with ' . $key . '">' . $key . '</a> ';
}
}
$tags = array('weddings' => 32, 'birthdays' => 41, 'landscapes' => 62, 'ham' => 51, 'chicken' => 23, 'food' => 91, 'turkey' => 47, 'windows' => 82, 'apple' => 27);
printTagCloud($tags);
以上是关于PHP 标签云的主要内容,如果未能解决你的问题,请参考以下文章
PHP 基于词频的PHP标签云
wordpress自定义标签云与随机获取标签的方法详解_php技巧 - PHP
PHP 标签云
PHP 标签云与圆角字体大小
PHP Wordpress基本标签云
PHP 创建标签云