I have taken the last code and I am trying to use it, in fact it works fine apart from it missing one of the words in the text.
if you look at the text you will see elit appears twice but when you run the script it does not appear in the result.
Any ideas?
PS, the data in my page will be appended to other text before processing hence the 2 lots of $text.
<?php
echo "<strong>Original text</strong><br />";
$text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
$text .= "<br />Ut enim ad minim consectetur adipisicing elit, quis nostrud exercitation ullamco laboris elit ut aliquip ex ea commodo consequat.";
echo "<pre>".$text."</pre><br>";
$Line_Breaks_Find = array("<br>", "<br />", "<br/>", "\r", "\n", ".", ",", " ");
$Line_Breaks_Replace = " ";
$text = str_ireplace($Line_Breaks_Find, $Line_Breaks_Replace, $text);
echo "<strong>Modified text (Strip out unwanted tag, punctuation etc)</strong><br />";
echo "<pre>".$text."</pre><br>";
$text = explode(' ',$text);
foreach ($text as $key => $word ) {
if (strlen($word) >4) {
$words[] = $word;
}
}
$count = array_count_values($words);
array_multisort($count,SORT_DESC);
$i = 1;
$VarsString ="Keywords";
foreach ($count as $key => $value) {
if( $i <= 20 ) {
$keyword[] = $key; # will give an array of the top 20 words
echo 'Number of occurances:<b> '.$value.' </b>of word: <b>'.$key."</b><br>\n";
$VarsString .= ", ".$key;
$i++;
}
}
echo "<br>".$VarsString;
?>