This is what I need to do:
I've created a input box for the user - please test on localhost
They have to enter a minimum of 100 words.
If they input less than a 100 words they should be advised and enabled to correct it.
What the code should do
1. The first is to clean the text. Remove punctuation from it and convert everything
to lower case. Remove all stop words. words like the, and, you etc.,
2. The code should count the number of occurrences of each word in the text.
3. Once you know how many times the words appear in the text you can construct your
cloud.
Cloud Construction:
The tag cloud must always consist of 20 tags which must be sorted alphabetically.
If the user lets say entered 150 words, you have to select the 20 words which occurred most and display these in the cloud.
Must implement a clearly visible visual hierarchy to distinguish between more and less important terms.
User Options:
When the tag cloud is displayed to the end user, you should provide him with the option to
update the tag cloud by adding additional text to it.
It is very important, therefore, that you store the original text entered by the user in a session variable and combine it with any new text he enters.
Remember that the new cloud should be constructed using both the original and the new text.
Alternatively the user must have the option to create a completely new tag cloud.
index.php
Code: Select all
<?php
if(isset($_POST['submitted'])) {
if(!strlen(trim($_POST['text']))) {
print "<span style='color:red;font-weight:bold;'>Please enter some text!!</span><p/>";
include('form.php');
}
else {
// format text
$cloud_one_text = $_POST['text'];
$cloud_one_text = strtolower(stripslashes($cloud_one_text));
$cloud_one_text = ereg_replace('[^a-zA-Z ]+', '', $cloud_one_text);
// remove stopwords
$stopwords = array("a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along",
"already", "also","although","always","am","among", "amongst", "amoungst", "amount", "an", "and", "another", "any","anyhow","anyone","anything","anyway",
"anywhere", "are", "around", "as", "at", "back","be","became", "because","become","becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below",
"beside", "besides", "between", "beyond", "bill", "both", "bottom","but", "by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry", "de", "describe",
"detail", "do", "done", "down", "due", "during", "each", "eg", "eight", "either", "eleven","else", "elsewhere", "empty",
"enough", "etc", "even", "ever", "every", "everyone", "everything",
"everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for",
"former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give",
"go","had", "has", "hasnt", "have", "he", "hence", "her", "here", "hereafter", "hereby", "herein",
"hereupon", "hers", "herself", "him", "himself", "his", "how", "however", "hundred", "ie", "if", "in",
"inc", "indeed", "interest", "into", "is", "it", "its", "itself", "keep", "last", "latter",
"latterly", "least", "less", "ltd", "made", "many", "may", "me", "meanwhile", "might", "mill", "mine",
"more", "moreover", "most", "mostly", "move", "much", "must", "my", "myself", "name", "namely",
"neither", "never", "nevertheless", "next", "nine", "no", "nobody", "none", "noone", "nor", "not",
"nothing", "now", "nowhere", "of", "off", "often", "on", "once", "one", "only", "onto", "or", "other",
"others", "otherwise", "our", "ours", "ourselves", "out", "over", "own","part", "per", "perhaps",
"please", "put", "rather", "re", "same", "see", "seem", "seemed", "seeming", "seems", "serious",
"several", "she", "should", "show", "side", "since", "sincere", "six", "sixty", "so", "some", "somehow", "someone",
"something", "sometime", "sometimes", "somewhere", "still", "such", "system", "take", "ten", "than", "that",
"the", "their", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein",
"thereupon", "these", "they", "thickv", "thin", "third", "this", "those", "though", "three", "through", "throughout",
"thru", "thus", "to", "together", "too", "top", "toward", "towards", "twelve", "twenty", "two", "un", "under", "until",
"up", "upon", "us", "very", "via", "was", "we", "well", "were", "what", "whatever", "when", "whence", "whenever", "where",
"whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither",
"who", "whoever", "whole", "whom", "whose", "why", "will", "with", "within", "without", "would", "yet", "you",
"your", "yours", "yourself", "yourselves", "the");
$cloud_one_text = preg_replace('/\b('.implode("|",$stopwords).')\b/i', '', $cloud_one_text);
// extract words
$cloud_one_words = explode(' ',$cloud_one_text);
$cloud_one_word_count = count($cloud_one_words);
if($cloud_one_word_count < 100) {
print"<span style='color:red;font-weight:bold;'> You must enter atleast 100 words!</span><p/>";
include('form.php');
}
else {
print "Thanks for entering the required amount of words";
// remove empty words
foreach($cloud_one_words as $key => $word) {
if(!strlen($word)) {
unset($cloud_one_words[$key]);
}
}
$cloud_one_word_occurances = array_count_values($cloud_one_words);
print "<pre>";
print_r($cloud_one_word_occurances);
print "</pre>";
exit();
}
}
}
else {
include('form.php');
}
?>Code: Select all
<form name='cloud_constructor' method='post' action='index.php'>
<table cellspacing='10px'>
<tr><td style="vertical-align:top;color:white;font-family:tahoma;font-size:12;">Please enter some text and click submit to create a cloud: </td><td><textarea name='text' rows='10' cols='30'></textarea>
</table>
<input type="hidden" name="submitted" value="TRUE"/>
<input type='submit' value='Submit'/>
</form>j