php 标签云效果(简单示例,入门参考)
生活随笔
收集整理的這篇文章主要介紹了
php 标签云效果(简单示例,入门参考)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
|
本文介紹一段php 標簽云效果的實現代碼,原理很簡單,實現的方法略顯質樸,呵呵。有興趣研究php 云標簽的朋友作個參考吧。
分享一段php 標簽云的實現代碼。 代碼:
<?php
/**
* php 標簽云
*
* @package WNiaoBlog
*
* @subpackage Tag
*/
//Connect the database
//include('../include/config.php'); //加載配置文件
/**
* CountTag() - Statistics labels appear the number,and the data to be stored in the two array
*
* GetTag() - Access the Tag's Labels from the database
*/
function CountTag($String){
$TagString = $String;
//echo $TagString."
";
$Tags = explode(",",$TagString);
$n = 1;
$i = 0;
$Continue = TRUE;
//echo $Tags[1]."
";
//in case no-label's article
while($Tags[$n] OR $Tags[++$n] OR $Tags[++$n] ){
$EachTag = $Tags[$n++];
//echo $EachTag."
";
$Continue = TRUE;
for($i=0;$Continue;$i++){
if( $EachTagStr[$i][0] ) {
if( $EachTagStr[$i][0] == $EachTag ){
$EachTagStr[$i][1]++;
$Continue = FALSE;
}
else {
if( $EachTagStr[$i+1][0] ) $Continue = TRUE;
else {
$EachTagStr[$i+1][0] = $EachTag;
$EachTagStr[$i+1][1] = 1;
$Continue = FALSE;
}
}
} else { //initialize the array $EachTagStr[][]
$EachTagStr[$i][0] = $EachTag;
$EachTagStr[$i][1] = 1;
$Continue = FALSE;
}
}
}
return $EachTagStr;
}
function ShowTag($Row,$ablink){
$i = 0;
while($Row[$i][0]){
$EachTag = $Row[$i][0];
$EachCount = $Row[$i][1];
$Size = SetSize($EachCount);
echo " ".$EachTag."(".$EachCount.")"." ";
$i++;
}
}
function GetTag(){
$QuerySet = mysql_query("select * from article");
while($Row = mysql_fetch_array($QuerySet)){
$Tag = $Row['tag'];
$TagString = $TagString.",".$Tag;
}
return $TagString;
}
function SetSize($Size){
$Size += 10;
if($Size > 30)
$Size = 30;
return $Size;
}
//Go
echo "
";
echo "標簽云";
$String = GetTag();
$Row = CountTag($String);
ShowTag($Row,$ablink);
echo "
";
?>
登錄后復制 |
總結
以上是生活随笔為你收集整理的php 标签云效果(简单示例,入门参考)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [USACO1.5]回文质数 Prime
- 下一篇: POJ 2230 Watchcow 欧拉