A PHP tag cloud class
include 'classes/tagcloud.php';
$cloud = new tagcloud();
$cloud->addTag("tag-cloud");
$cloud->addTag("programming");
echo $cloud->render();
$cloud->addString("This is a tag-cloud script, written by Del Harvey.");
$cloud->addString("I wrote this tag-cloud class because I just love writing code.");
$cloud->addTags(array('tag-cloud','php','github'));
$cloud->setRemoveTag('github');
$cloud->setRemoveTags(array('del','harvey'));
$cloud->addTag(array('tag' => 'php', 'url' => 'http://www.php.net', 'colour' => 1));
$cloud->addTag(array('tag' => 'ajax', 'url' => 'http://www.php.net', 'colour' => 2));
$cloud->addTag(array('tag' => 'css', 'url' => 'http://www.php.net', 'colour' => 3));
$cloud->setMinLength(3);
$cloud->setLimit(10);
$cloud->setOrder('tag','ASC');
$cloud->setOrder('size','DESC');
$cloud->setOrder('colour','DESC');
echo $cloud->render();
$cloud = new tagcloud();
$getBooks = mysql_query("SELECT title FROM `tags`");
if ($getBooks) {
while ($rowBooks = mysql_fetch_assoc($getBooks)) {
$cloud->addTag($rowBooks['title']);
}
}
$myCloud = $cloud->render('array');
if (is_array($myCloud)) {
foreach ($myCloud as $key => $value) {
echo ' <a href="./tags/'.urlencode($value['tag']).'" style="font-size: 1.'.($value['range']).'em">'.$value['tag'].'</a> ';
}
}
$cloud = new tagcloud();
$f = 'tags.txt'; // Filename of the text file
if ($h = fopen($f, 'r')) {
if (!feof($h)) {
do {
$c = fread($h, 4096);
$t = explode('|', $c);
foreach ($t as $k => $v) {
$cloud->addTag($v);
}
} while (!feof($h));
}
}
echo $cloud->render();