php 创建tag云输出(不同标签字体不同大小)

前端之家收集整理的这篇文章主要介绍了php 创建tag云输出(不同标签字体不同大小)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下:
  1. <?PHP
  2. /**
  3. * 创建tag云输出标签字体大小不同)
  4. *
  5. * @param
  6. * @arrange (512.笔记) jb51.cc
  7. **/
  8. function getCloud( $data = array(),$minFontSize = 12,$maxFontSize = 30 )
  9. {
  10. $minimumCount = min( array_values( $data ) );
  11. $maximumCount = max( array_values( $data ) );
  12. $spread = $maximumCount - $minimumCount;
  13. $cloudHTML = '';
  14. $cloudTags = array();
  15. $spread == 0 && $spread = 1;
  16. foreach( $data as $tag => $count )
  17. {
  18. $size = $minFontSize + ( $count - $minimumCount )
  19. * ( $maxFontSize - $minFontSize ) / $spread;
  20. $cloudTags[] = '<a style="font-size: ' . floor( $size ) . 'px'
  21. . '" class="tag_cloud" href="#" title="\'' . $tag .
  22. '\' returned a count of ' . $count . '">'
  23. . htmlspecialchars( stripslashes( $tag ) ) . '</a>';
  24. }
  25. return join( "\n",$cloudTags ) . "\n";
  26. }
  27. /**************************
  28. **** Sample usage ***/
  29. $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);
  30. echo getCloud($arr,12,36);
  31. /*** 来自:编程之家 jb51.cc(jb51.cc) ***/
  32. ?>

猜你在找的PHP相关文章