Thanks for Your Donations
Latest Releases

Metro Last Light

Iron Sky Invasion

Deadly Premonition The Director's Cut

Dragons Dogma Dark Arisen

Star Trek

Dead Island Riptide

Injustice Gods Among Us

Defiance
Results 1 to 3 of 3

Thread: Easy PHP Word Cloud +How to

  1. #1
    romaan's Avatar
    romaan is offline Universal Moderator Athanatos
    Join Date
    Jan 2011
    Location
    Sweet Home
    Posts
    4,180
    Blog Entries
    10
    Rep Power
    29

    Default Easy PHP Word Cloud +How to

    Hi,

    I would like to share easy way to make word tag cloud using PHP,

    I got the main logic for word cloud from Google Word Cloud code

    as its noob friendly so I would like make it as easy as I can,

    First you have to to make a CSS for your words

    Code:
    <style type="text/css">
    .word-cloud {font-family: arial; font-size: 10px; }
    .word-cloud-1 {font-size: 10px; color: #acc1f3; }
    .word-cloud-2 {font-size: 14px; color: #86a0dc; }
    .word-cloud-3 {font-size: 18px; color: #607ec5; }
    .word-cloud-4 {font-size: 22px; color: #264ca2; }
    .word-cloud-5 {font-size: 26px; color: #133b97; }
    .word-cloud-6 {font-size: 32px; color: #002a8b; }
    .word-cloud-7 {font-size: 36px; color: #071a41; }
    .word-cloud-8 {font-size: 40px; color: #081122; }
    .word-cloud-9 {font-size: 44px; color: #000000; }
    </style>
    so the smallest word size is 10px and largest is 44px
    Code:
    $factor = 0.5;
    $starting_font_size = 10;
    $tag_separator = '&nbsp; &nbsp;';
    $max_count = count($response);

    in PHP you have to defined the factor and and max response, where $reponse is a two dim array having word and its count like
    Code:
    $response = array ( 0 => array (
                                     'Word' => 'PS3',
                                     'Count' => '50'
                                    ) ,
                                1 => array (
                                     'Word' => 'ISO',
                                     'Count' => '50'
                                    ) 
                             );
    Now the calculation and display part

    Code:
    foreach($response as $key => $value )
    {
            $weight = $value['Count'];
    	$tag = $value['Word'];
    	$x = round(($weight * 100) / $max_count) * $factor;
            $font_size = $starting_font_size + $x;
     	
    	$class = 'class="word-cloud-1"';
    
    	if($font_size <=20)
    		$class = 'class="word-cloud-1"';
    	else if($font_size <=30)
     		$class = 'class="word-cloud-2"';
    	elseif($font_size <=50)
     		$class = 'class="word-cloud-3"';
    	elseif($font_size <=65)
     		$class = 'class="word-cloud-4"';		
    	elseif($font_size <=80)
     		$class = 'class="word-cloud-5"';
    	elseif($font_size <=100)
     		$class = 'class="word-cloud-6"';
    	elseif($font_size <=150)
     		$class = 'class="word-cloud-7"';
    	elseif($font_size <=220)
     		$class = 'class="word-cloud-8"';
    	else
    		$class = 'class="word-cloud-9"';
    			
    	
              echo "<span ".$class.">".$tag."</span>".$tag_separator;
    }
    Code can be more optimize, as I use too many variables to explain in details, and used too many if conditions..

    Sample Output :

    Last edited by romaan; 29th February 2012 at 07:56 AM.
    Would You like to Say Thanks Or +Rep Please Click Icon at Bottom Left of My Post
    Safe Steps For Install Rogero CEX-4.21 CFW
    Run Backup 3.6+ Games on DEX, Noob Friendly With Pictures and Videos
    Get Your User ID For ReActPSN | Tutorial Multiman NTFS Support | Tutorial SlideShow Dynamic PS3 Theme | Tutorial PS3usercheat PKG Guide - For Non-Dongle Users
    Uploading Rules & Clarification
    Credits are not a requirement for posting content. None of the 99% of uploaders on this site post credits. It is not a requirement. Listing credits is by choice if you want to post them or not.

  2. #2
    ireggae's Avatar
    ireggae is offline Universal Moderator Hall of Famer
    Join Date
    Jan 2011
    Location
    Xbox Live
    Posts
    5,196
    Rep Power
    26

    Default

    thanks and i ill start to post more. been very busy and same happened with VenomousX
    Check Out the Pc Zone! From Movies, Apps, and Mobile to Music and Anime!
    http://www.ps3iso.com/pc-zone/

  3. #3
    romaan's Avatar
    romaan is offline Universal Moderator Athanatos
    Join Date
    Jan 2011
    Location
    Sweet Home
    Posts
    4,180
    Blog Entries
    10
    Rep Power
    29

    Default

    Quote Originally Posted by ireggae View Post
    thanks and i ill start to post more. been very busy and same happened with VenomousX
    me also got busy in other stuff :( no time for gaming as well :(
    Would You like to Say Thanks Or +Rep Please Click Icon at Bottom Left of My Post
    Safe Steps For Install Rogero CEX-4.21 CFW
    Run Backup 3.6+ Games on DEX, Noob Friendly With Pictures and Videos
    Get Your User ID For ReActPSN | Tutorial Multiman NTFS Support | Tutorial SlideShow Dynamic PS3 Theme | Tutorial PS3usercheat PKG Guide - For Non-Dongle Users
    Uploading Rules & Clarification
    Credits are not a requirement for posting content. None of the 99% of uploaders on this site post credits. It is not a requirement. Listing credits is by choice if you want to post them or not.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •