PDA

View Full Version : Keyword generation and PHP


cocoonfx
11-24-2011, 03:34 PM
Hi

I am trying to generate some keywords to form a tag cloud in wordpress. I know there are plugins but I am trying to develop a bit code which can take the words used in the posts.

So far I have the following code which breaks the text into individual words

$content = get_the_content();
$withCounts = explode( ' ', $content );
print_r ($withCounts);

Result:
Array ( [0] => This [1] => is [2] => an [3] => example [4] => page. [5] => It's [6] => different [7] => from [8] => a [9] => blog [10] => post [11] => because [12] => it [13] => will [14] => etc....

How do I get rid of the Array ( and the => [] etc... and also I have tried to do an if statement to remove any words smaller than 3 words.

Any pointers please?

davidj
11-27-2011, 09:34 PM
You will need an algorithm to do this as choosing words based on length wont work. You will pick up words like 'because' or 'example'. You will need to filter on Nouns which are stored in a database.


To remove words of a set length... (Although don't think this is the right tool for the job!)




foreach($withCounts as $value=>$key){

if(strlen($value) < 4){

unset($withCounts[$key]);

}

}