Php implements tag cloud generation based on word frequency. php word frequency tag cloud _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php implements the tag cloud generation method based on word frequency, and php word frequency tag cloud. Php implements the tag cloud generation method based on word frequency. This document describes how php generates a tag cloud based on word frequency. Share it with you for your reference. The details are as follows: php implements the tag cloud generation method based on word frequency, and php word frequency tag cloud

This example describes how to generate a tag cloud based on word frequency in php. Share it with you for your reference. The details are as follows:

A piece of text is given here to analyze the word frequency distribution of the text and generate a tag cloud

<?php/** * Tag cloud demo based on word frequency * @author: unknown * @since: 2007-02-27 */// Store frequency of words in an array$freqData = array();// Random words$lorem = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.Phasellus vestibulum ullamcorper tortor. Aenean quis lacus quis nequeadipiscing ultricies. Pellentesque tincidunt ligula vitae nibh ornarepharetra. Proin dignissim tortor. Donec et ipsum nec tellus gravidatempor. Aliquam ullamcorper purus vel felis. Praesent faucibus.Curabitur porta. Nulla in lorem quis mi lacinia fringilla. Integeradipiscing mi quis felis. Pellentesque habitant morbi tristique senectuset netus et malesuada fames ac turpis egestas. Quisque sagittis ante inarcu. Sed libero enim, venenatis sit amet, vestibulum at, porttitor id,neque. Vestibulum ornare semper erat. Sed tincidunt nibh et massa. Crassed diam. Quisque blandit enim.Sed nonummy. Aenean mollis turpis quis enim. Nam massa nulla, variusmolestie, aliquet et, feugiat eget, nisi. Sed mollis, leo ut pretiumplacerat, nibh turpis egestas ipsum, sed aliquam neque enim in risus.Nullam nisl. Sed tincidunt leo quis tellus. Mauris non lorem. Aeneantristique justo at arcu. Fusce et lorem. Nam sodales. Mauris condimentumdiam. Nam commodo. Cum sociis natoque penatibus et magnis dis parturientmontes, nascetur ridiculus mus. Cras ac risus. Proin et dolor laoreet migravida sodales. Duis bibendum, ipsum posuere egestas posuere, dui lacusfeugiat turpis, id tincidunt urna est sit amet est. Cras eu sem.";// Get inpidual words and build a frequency tableforeach( str_word_count( $lorem, 1 ) as $word ){ // For each word found in the frequency table,  //increment its value by one array_key_exists($word,$freqData)?$freqData[$word]++:$freqData[$word]=0;}// ==============================================================// = Function to actually generate the cloud from provided data =// ==============================================================function getCloud($data = array(), $minFontSize = 12, $maxFontSize = 30){ $minimumCount = min( array_values( $data ) ); $maximumCount = max( array_values( $data ) ); $spread = $maximumCount - $minimumCount; $cloudHTML = ''; $cloudTags = array(); $spread == 0 && $spread = 1; foreach( $data as $tag => $count ) { $size = $minFontSize + ( $count - $minimumCount ) * ( $maxFontSize - $minFontSize ) / $spread; $cloudTags[] = '' . htmlspecialchars( stripslashes( $tag ) ) . ''; } return join( "\n", $cloudTags ) . "\n";} ?> Tag Cloud Demo  Sample Tag Cloud 

<?php echo getCloud( $freqData ) ?>

I hope this article will help you with php programming.

Examples in this article describe how php generates a tag cloud based on word frequency. Share it with you for your reference. Details: here...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.