Home >Backend Development >PHP Tutorial >PHP creates tag cloud function_PHP tutorial

PHP creates tag cloud function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:30:231120browse

PHP creates a tag cloud function, which generates a series of link effects from tags in different sizes, which looks interesting.

 01

 02function getCloud($data = array(),$minFontSize = 12,$maxFontSize = 30)

 03{

 04$minimumCount = min( array_values( $data ) );

 05$maximumCount = max( array_values( $data ) );

 06$spread = $maximumCount - $minimumCount;

 07$cloudHTML = '';

 08$cloudTags = array();

 09$spread == 0 && $spread = 1;

 10foreach( $data as $tag => $count )

 11{

 12$size = $minFontSize + ( $count - $minimumCount )

 13* ( $maxFontSize - $minFontSize ) / $spread;

 14$cloudTags[] = '

 16'' returned a count of ' . $count . '">'

 17. htmlspecialchars( stripslashes( $tag ) ) . '';

 18}

 19return join( "n", $cloudTags ) . "n";

 20}

 21?>

Call example:

View sourceprint?

1

 2$arr = Array('CodeFans' => 35, 'Adobe' => 22, 'Background' => 43,

 3'Blur' => 18, 'Canvas' => 33, 'Class' => 15, 'Design' => 8, 'Encode' => 12, 'Encryption' => 30,

 4'Extract' => 28, 'Filters' => 42);

5echo getCloud($arr, 12, 36);

 6?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/765430.htmlTechArticlePHP creates a tag cloud function, which generates a series of link effects from tags in different sizes, which looks interesting. 01 ?php 02function getCloud($data = array(),$minFontSize = 12,$maxFontSize...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn