一个简单的标签云图算法(Tag Clouds )

这是一个很简单的tag云图算法,也是偶然间在网上找到的,一直都在用 ,算法十分简单和实用。虽然代码是用PHP的,但是很容易移至到其它程序语言asp.net,java等。

< ?php function tag_cloud($tags) { $maxsize = 38; $minsize = 12; $maxval = max(array_values($tags)); $minval = min(array_values($tags)); $spread = $maxval - $minval; $step = ($maxsize - $minsize) / ($spread); foreach ($tags as $key => $value) {
$size = round($minsize + (($value – $minval) * $step));
echo ‘‘.$key.’ ‘;
}
}

$tags = array(‘php’=>30, ‘javascript’=>24, ‘java’=>17, ‘python’=>26, ‘ruby’=>17);

tag_cloud($tags);

?>

“一个简单的标签云图算法(Tag Clouds )”的2个回复

  1. 通过搜索进来,虽然是PHP的, 我转换为JAVA的了,要是再支持显示不同的颜色就完美了

  2. Apple now has Rhapsody as an app, which is a great start, but it is currently hampered by the inability to store locally on your iPod, and has a dismal 64kbps bit rate. If this changes, then it will somewhat negate this advantage for the Zune, but the 10 songs per month will still be a big plus in Zune Pa&72#8s1s; favor.

发表评论

电子邮件地址不会被公开。