Skip to content
Latest commit db881a6 Aug 5, 2014 @lotsofcode Update

PHP Tag Cloud


Build Status

Basic usage

$cloud = new TagCloud();
echo $cloud->render();

Convert a string

$cloud->addString("This is a tag-cloud script, written by Del Harvey. I wrote this tag-cloud class because I just love writing code.");

Adding multiple tags


Removing a tag


Removing multiple tags


More complex adding

$cloud->addTag(array('tag' => 'php', 'url' => '', 'colour' => 1));
$cloud->addTag(array('tag' => 'ajax', 'url' => '', 'colour' => 2));
$cloud->addTag(array('tag' => 'css', 'url' => '', 'colour' => 3));

Set the minimum length required


Limiting the output


Set the order


Set a custom HTML output

$cloud->setHtmlizeTagFunction(function($tag, $size) use ($baseUrl) {
  $link = '<a href="'.$baseUrl.'/'.$tag['url'].'">'.$tag['tag'].'</a>';
  return "<span class='tag size{$size} colour-{$tag['colour']}'>{$link}</span> ";

Outputting the cloud (shown above)

echo $cloud->render();


By default, all accented characters will be converted into their non-accented equivalent, this is to circumvent duplicate similar tags in the same cloud, to disable this functionality and display the UTF-8 characters you can do the following:

$tagCloud->setOption('transliterate', false);

More usages on in a prettier format can be found here:


To run the unit test suite, first install the dependencies:

curl -s | php
php composer.phar install

Then execute phpunit in the root directory


Submitting pull requests

Indentation style, size and encoding should be followed as per .editorconfig settings.

Something went wrong with that request. Please try again.