Jump to content

Count


14862875

Recommended Posts

I'm struggling to display only the 20 most used words in tags that i'm trying to display..

 

here's my code:

 

<?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=str_replace(".","",$cloud_one_text);
$cloud_one_text=str_replace("'","",$cloud_one_text);
$cloud_one_text=str_replace(":","",$cloud_one_text);
$cloud_one_text=str_replace(";","",$cloud_one_text);
$cloud_one_text=str_replace(",","",$cloud_one_text);
$cloud_one_text=str_replace("!","",$cloud_one_text);
$cloud_one_text=str_replace("?","",$cloud_one_text);
$cloud_one_text=str_replace("_","",$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"<b>Thanks for entering the required amount of words</b><br/><br/>";

$tags=array();

foreach($cloud_one_words as $cloud_one_word)

{

$cloud_one_word=strtolower($cloud_one_word);
if(isset($tags[$cloud_one_word]))

{
  $tags[$cloud_one_word]+=1;
  
}

else

{
  $tags[$cloud_one_word]=1;
  
} 

}

ksort($tags);

foreach($tags as $tag=>$size)

{
$size += 12;
echo "<span style=\"font-size:{$size}px\"> $tag </span>"; 

} 
   
}
}
}
else
{
include('form.php');

}

?>

Link to comment
https://forums.phpfreaks.com/topic/159168-count/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.