• home
  • forum
  • my
  • kt
  • download
  • Creating a Tag Cloud Using PHP

    Author: 2007-08-24 15:48:12 From:

    function printTagCloud($tags) {
            // $tags is the array
           
            arsort($tags);
           
            $max_size = 32; // max font size in pixels
            $min_size = 12; // min font size in pixels
           
            // largest and smallest array values
            $max_qty = max(array_values($tags));
            $min_qty = min(array_values($tags));
           
            // find the range of values
            $spread = $max_qty - $min_qty;
            if ($spread == 0) { // we don't want to divide by zero
                    $spread = 1;
            }
           
            // set the font-size increment
            $step = ($max_size - $min_size) / ($spread);
           
            // loop through the tag array
            foreach ($tags as $key => $value) {
                    // calculate font-size
                    // find the $value in excess of $min_qty
                    // multiply by the font-size increment ($size)
                    // and add the $min_size set above
                    $size = round($min_size + (($value - $min_qty) * $step));
           
                    echo '<a href="#" style="font-size: ' . $size . 'px" title="' . $value . ' things tagged with ' . $key . '">' . $key . '</a> ';
            }
    }

    $tags = array('weddings' => 32, 'birthdays' => 41, 'landscapes' => 62, 'ham' => 51, 'chicken' => 23, 'food' => 91, 'turkey' => 47, 'windows' => 82, 'apple' => 27);

    printTagCloud($tags);

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (6)
      Discussion Boards (7)
      E Commerce (6)
      Email Systems (9)
      Error Handling (5)
      File Manipulation (10)
      Flash and PHP (4)
      Form Processing (7)
      Guestbooks (8)
      Image Manipulation (3)
      Installing PHP (5)
      Introduction to PHP (9)
      Link Indexing (6)
      Mailing List Management (8)
      Miscellaneous (10)
      Networking (6)
      News Publishing (6)
      OOP (8)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (5)
      Postcards (0)
      Randomizing (8)
      Redirection (8)
      Searching (6)
      Security (6)
      Site Navigation (7)
      User Authentication (10)
      WAP and WML (7)
      Web Fetching (0)
      Web Traffic Analysis (11)
      XML and PHP (0)

    New

    Hot