首頁 > 後端開發 > php教程 > php實作標籤雲的一段程式碼

php實作標籤雲的一段程式碼

WBOY
發布: 2016-07-25 09:03:26
原創
839 人瀏覽過
  1. /**
  2. * WNiaoBlog Tag Template ShowTag
  3. *
  4. * @package WNiaoBlog
  5. *
  6. * @subpackage Tag
  7. */
  8. //Connect the database
  9. //include('../include/config.php');
  10. /**
  11. * CountTag() - Statistics labels appear the number,and the data to be stored in the two array
  12. *
  13. * GetTag() - Access the Tag's Labels from the database
  14. */
  15. function CountTag($String){
  16. $TagString = $String;
  17. //echo $TagString."
  18. ";
  19. $Tags = explode(",",$TagString);
  20. $n = 1;
  21. $i = 0;
  22. $Continue = TRUE;
  23. //echo $Tags[1]."
  24. ";
  25. //in case no-label's article
  26. while($Tags[$n] OR $Tags[++$n] OR $Tags[++$n] ){
  27. $EachTag = $Tags[$n++];
  28. //echo $EachTag."
  29. ";
  30. $Continue = TRUE;
  31. for($i=0;$Continue;$i++){
  32. if( $EachTagStr[$i][0] ) {
  33. if( $EachTagStr[$i][0] == $EachTag ){
  34. $EachTagStr[$i][1]++;
  35. $Continue = FALSE;
  36. }
  37. else {
  38. if( $EachTagStr[$i+1][0] ) $Continue = TRUE;
  39. else {
  40. $EachTagStr[$i+1][0] = $EachTag;
  41. $EachTagStr[$i+1][1] = 1;
  42. $Continue = FALSE;
  43. }
  44. }
  45. } else { //initialize the array $EachTagStr[][]
  46. $EachTagStr[$i][0] = $EachTag;
  47. $EachTagStr[$i][1] = 1;
  48. $Continue = FALSE;
  49. }
  50. }
  51. }
  52. return $EachTagStr;
  53. }
  54. function ShowTag($Row,$ablink){
  55. $i = 0;
  56. while($Row[$i][0]){
  57. $EachTag = $Row[$i][0];
  58. $EachCount = $Row[$i][1];
  59. $Size = SetSize($EachCount);
  60. echo " < a style='color:BLUE ; font-size:".$Size." ' onMouseOver=this.style.color='#900000' onMouseOut=this.style.color='BLUE' href='".$ablink."tag?tag=".$EachTag."' target='_self' > ".$EachTag."(".$EachCount.")"." ";
  61. $i++;
  62. }
  63. }
  64. function GetTag(){
  65. $QuerySet = mysql_query("select * from article");
  66. while($Row = mysql_fetch_array($QuerySet)){
  67. $Tag = $Row['tag'];
  68. $TagString = $TagString.",".$Tag;
  69. }
  70. return $TagString;
  71. }
  72. function SetSize($Size){
  73. $Size += 10;
  74. if($Size > 30)
  75. $Size = 30;
  76. return $Size;
  77. }
  78. //Go
  79. echo "
  80. ";
  81. echo "标签云";
  82. $String = GetTag();
  83. $Row = CountTag($String);
  84. ShowTag($Row,$ablink);
  85. echo "
  86. ";
  87. ?>
复制代码


來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板