PHP Tag Cloud

Description

A tag cloud is a visual depiction of user-generated tags used typically to describe the content of web sites. Tags are usually single words and are typically listed alphabetically, and the importance of a tag is shown with font size or color. In this stuff i am going to show you how to create a basic word / tag using php classes for easy inclusion.

Features
Specification
Methods
In action

$obj = new tagCloud();
$obj->addWord(array('word'=>'actionscript','size'=>10)); 
$obj->addWord(array('word'=>'adobe','size'=>22));
$obj->addWord(array('word'=>'array','size'=>44));
$obj->addWord(array('word'=>'background','size'=>34));
$obj->addWord(array('word'=>'blur','size'=>18,));
$obj->addWord(array('word'=>'canvas','size'=>33));
$obj->addWord(array('word'=>'class','size'=>15));
$obj->orderBy('word','ASC');//add order to the cloud
echo$obj->showCloud();
actionscript adobe adrian air ajax array asus atom attribute background blog blur canvas class color Palette constructor controller cpu crop css delimiter depth design digg element encode encryption extract filters flash float fluid function functions gaussian Blur google grafix graphics hCalendar hCard hdd hi5 hReview html hue ie illustrator image Ready javascript jobs jpeg keyboard laptop level liquify listener logo loops macromedia maps microformats motorola mozzila mushup opera patters php php4 php5 prototype ria safari script split tag w3c xhtml yahoo

$obj = new tagCloud();
$obj->addWord(array('word'=>'actionscript','size'=>10)); 
$obj->addWord(array('word'=>'adobe','size'=>22));
$obj->addWord(array('word'=>'array','size'=>44));
$obj->addWord(array('word'=>'background','size'=>34));
$obj->addWord(array('word'=>'blur','size'=>18,));
$obj->addWord(array('word'=>'canvas','size'=>33));
$obj->addWord(array('word'=>'class','size'=>15));
$obj->orderBy('word','DESC');//add order to the cloud
echo$obj->showCloud();
yahoo xhtml w3c tag split script safari ria prototype php5 php4 php patters opera mushup mozzila motorola microformats maps macromedia loops logo listener liquify level laptop keyboard jpeg jobs javascript image Ready illustrator ie hue html hReview hi5 hdd hCard hCalendar graphics grafix google gaussian Blur functions function fluid float flash filters extract encryption encode element digg design depth delimiter css crop cpu controller constructor color Palette class canvas blur blog background attribute atom asus array ajax air adrian adobe actionscript

ORDER RESULTS[DESC-size]

$obj = new tagCloud();
$obj->addWord(array('word'=>'actionscript','size'=>10)); 
$obj->addWord(array('word'=>'adobe','size'=>22));
$obj->addWord(array('word'=>'array','size'=>44));
$obj->addWord(array('word'=>'background','size'=>34));
$obj->addWord(array('word'=>'blur','size'=>18,));
$obj->addWord(array('word'=>'canvas','size'=>33));
$obj->addWord(array('word'=>'class','size'=>15));
$obj->orderBy('size','DESC');//add order to the cloud
echo$obj->showCloud();
loops adrian macromedia grafix filters hReview ie tag element opera attribute safari fluid mozzila hue javascript array gaussian Blur crop php4 hCard graphics background depth laptop script canvas css function air flash mushup patters xhtml atom microformats ria digg encryption hi5 liquify google extract html level maps prototype yahoo float adobe ajax cpu motorola constructor functions jobs w3c blur keyboard class jpeg controller split delimiter encode hdd image Ready logo php5 blog color Palette actionscript asus hCalendar listener php illustrator design

ORDER RESULTS[ASC-size]

$obj = new tagCloud();
$obj->addWord(array('word'=>'actionscript','size'=>10)); 
$obj->addWord(array('word'=>'adobe','size'=>22));
$obj->addWord(array('word'=>'array','size'=>44));
$obj->addWord(array('word'=>'background','size'=>34));
$obj->addWord(array('word'=>'blur','size'=>18,));
$obj->addWord(array('word'=>'canvas','size'=>33));
$obj->addWord(array('word'=>'class','size'=>15));
$obj->orderBy('size','ASC');//add order to the cloud
echo$obj->showCloud();
design illustrator actionscript asus hCalendar listener php blog color Palette encode hdd image Ready logo php5 delimiter controller split class jpeg blur keyboard constructor functions jobs w3c ajax cpu motorola adobe float extract html level maps prototype yahoo google digg encryption hi5 liquify atom microformats ria air flash mushup patters xhtml canvas css function background depth laptop script graphics hCard php4 crop array gaussian Blur hue javascript fluid mozzila attribute safari element opera ie tag hReview filters grafix macromedia adrian loops

$obj2 = new tagCloud();
$obj2->addWord(array('word'=>'actionscript','size'=>10)); 
$obj2->addWord(array('word'=>'adobe','size'=>22));
$obj2->addWord(array('word'=>'array','size'=>44));
$obj2->addWord(array('word'=>'background','size'=>34));
$obj2->addWord(array('word'=>'blur','size'=>18,));
$obj2->addWord(array('word'=>'canvas','size'=>33));
$obj2->addWord(array('word'=>'class','size'=>15));
$obj2->addWord(array('word'=>'color Palette','size'=>11));
$obj2->addWord(array('word'=>'crop','size'=>42));
$obj2->addWord(array('word'=>'delimiter','size'=>13));
$obj2->addWord(array('word'=>'depth','size'=>34));
$obj2->addWord(array('word'=>'design','size'=>8));
$obj2->addWord(array('word'=>'encode','size'=>12));
$obj2->addWord(array('word'=>'encryption','size'=>30));
$obj2->addWord(array('word'=>'extract','size'=>28));
$obj2->addWord(array('word'=>'filters','size'=>82));
echo$obj2->showCloud();
actionscript encryption array blur background delimiter filters crop encode design canvas extract depth class color Palette adobe

$obj3 = new tagCloud();
$obj3->addString("mecanica cuantica cuantica cuantica cuantica este o teorie 
fizica care descrie comportamentul materiei la nivelul atomic si subatomic 
fenomene pe care fizica newtoniana si electromagnetismul clasic nici nu le
pot explica");
echo$obj3->showCloud();
materiei si nici electromagnetismul la le este comportamentul mecanica atomic care pot fizica o subatomic descrie newtoniana pe clasic explica cuantica teorie nu fenomene nivelul

ORDER RESULTS[DESC-word]

$obj3 = new tagCloud();
$obj3->addString("mecanica cuantica cuantica cuantica cuantica este o teorie 
fizica care descrie  comportamentul materiei la nivelul atomic si subatomic 
fenomene pe carefizica newtoniana si electromagnetismul clasic nici nu le 
pot explica");
$obj3->orderBy('word','DESC');
echo$obj3->showCloud();
teorie subatomic si pot pe o nu nivelul nici newtoniana mecanica materiei le la fizica fenomene explica este electromagnetismul descrie cuantica comportamentul clasic care atomic

ORDER RESULTS[ASC-word]

$obj3 = new tagCloud();
$obj3->addString("mecanica cuantica cuantica cuantica cuantica este o teorie 
fizica care descrie comportamentul materiei la nivelul atomic si subatomic 
fenomene pe care fizica newtoniana si electromagnetismul clasic nici nu 
le pot explica");
$obj3->orderBy('word','ASC');
echo$obj3->showCloud();
atomic care clasic comportamentul cuantica descrie electromagnetismul este explica fenomene fizica la le materiei mecanica newtoniana nici nivelul nu o pe pot si subatomic teorie

SETUP LIMIT CLOUD

$obj4 = new tagCloud();
$obj4->addWord(array('word'=>'actionscript','size'=>10)); 
$obj4->addWord(array('word'=>'adobe','size'=>22));
$obj4->addWord(array('word'=>'array','size'=>44));
$obj4->addWord(array('word'=>'background','size'=>34));
$obj4->addWord(array('word'=>'blur','size'=>18,));
$obj4->addWord(array('word'=>'canvas','size'=>33));
$obj4->addWord(array('word'=>'class','size'=>15));
$obj4->addWord(array('word'=>'color Palette','size'=>11));
$obj4->addWord(array('word'=>'crop','size'=>42));
$obj4->addWord(array('word'=>'delimiter','size'=>13));
$obj4->addWord(array('word'=>'depth','size'=>34));
$obj4->addWord(array('word'=>'design','size'=>8));
$obj4->addWord(array('word'=>'encode','size'=>12));
$obj4->addWord(array('word'=>'encryption','size'=>30));
$obj4->addWord(array('word'=>'extract','size'=>28));
$obj4->addWord(array('word'=>'filters','size'=>82));
$obj4->setLimit(7);
echo$obj4->showCloud();
extract actionscript crop design encode color Palette

$obj5 = new tagCloud();
$obj5->addWord(array('word'=>'yahoo','size'=>10,'url'=>'http://www.yahoo.com')); 
$obj5->addWord(array('word'=>'adobe','size'=>22,'url'=>'http://www.adobe.com'));
$obj5->addWord(array('word'=>'google','size'=>44,'url'=>'http://www.google.com'));
$obj5->addWord(array('word'=>'flickr','size'=>34,'url'=>'http://www.flickr.com'));
$obj5->addWord(array('word'=>'amazon','size'=>18,'url'=>'http://www.amazon.com'));
$obj5->addWord(array('word'=>'hotmail','size'=>33,'url'=>'http://www.hotmail.com'));
$obj5->addWord(array('word'=>'excite','size'=>15,'url'=>'http://www.excite.com'));
$vectorInfo=$obj5->showCloud('array');
 foreach($vectorInfo as $arrayInfo)
   {
    echo"< a href='".$arrayInfo['url']."' title='".$arrayInfo['size']."posts' class=
    'word size".$arrayInfo['range']."'>".$arrayInfo['word']."< / a >"; 
   }
 excite hotmail adobe amazon google yahoo flickr

Retrieve data from MySQL database

$new_obj = new tagCloud();
include ('dbconnector.php');
$sql = "SELECT * FROM tags";
$query = mysql_query($sql);
$numbers = mysql_num_rows($query);

 if($numbers > 0)
    {
     while($row=mysql_fetch_assoc($query))
      {
         $new_obj->addWord(array('word'=>$row['tag_name'],'size'=>$row['tag_pondere']));       
      }

      $getVector = $new_obj->showCloud('array');
            
          if(is_array($getVector))
                {
                    foreach($getVector as $vectorInfo)
                      {                    
                          echo"< a href='#".$vectorInfo['word']."' 
                                   title='".$vectorInfo['size']." posts' 
                                   class='word size".$vectorInfo['range']."'>"
                                   .$vectorInfo['word'].
                                   "< /a > ";
                      }
                }   


    }//end if 

Unable to connect to database!Unable to select database!

Retrieve data from FILE TXT

$new_object = new tagCloud();
$filename ="cloud.txt";
$separator = "|";
$fp = fopen($filename,"r");

if(!feof($fp))
{
do
{
$c = fread($fp,4096);
$t = explode($separator,$c);
   foreach($t as $k=>$v) $new_object->addWord($v);
}while(!feof($fp));
}
echo$new_object->showCloud();
flickr linux windows microformats amazon asus mac google apple yahoo