Created
September 10, 2014 09:21
-
-
Save khoand0000/42cc4c47635281b62618 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php function getCloud( $data = array(), $minFontSize = 12, $maxFontSize = 30 ) | |
{ | |
$minimumCount = min($data); | |
$maximumCount = max($data); | |
$spread = $maximumCount - $minimumCount; | |
$cloudHTML = ''; | |
$cloudTags = array(); | |
$spread == 0 && $spread = 1; | |
foreach( $data as $tag => $count ) | |
{ | |
$size = $minFontSize + ( $count - $minimumCount ) | |
* ( $maxFontSize - $minFontSize ) / $spread; | |
$cloudTags[] = '<a style="font-size: ' . floor( $size ) . 'px' | |
. '" class="tag_cloud" href="#" title="\'' . $tag . | |
'\' returned a count of ' . $count . '">' | |
. htmlspecialchars( stripslashes( $tag ) ) . '</a>'; | |
} | |
return join( "\n", $cloudTags ) . "\n"; | |
} | |
$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); | |
echo getCloud($arr, 12, 36); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment