Forum Moderators: coopster

Message Too Old, No Replies

Getting Keywords from text

         

phprockz

5:57 pm on Apr 3, 2006 (gmt 0)

10+ Year Member



Hi,
Iam trying to get keywords of article from database(mysql).

Ex this is text from db "WW is one of the best disscussion forums in world"

I need keywords from that post to my meta keywords like WW,best,discussion,forums like that.Please suggest me any idea.

FourDegreez

8:20 pm on Apr 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wrote something like that in java. Each word in the text was added to an array. If the word already exists in the array, increment its counter. Don't add words to the array you don't want, like "the", "an", "this", etc. Finally sort the array by the counter, so that the most frequently used words appear on top and take the top ten or so as the keywords.

Sorry, never did something like it in PHP.

coopster

12:04 am on Apr 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That method would work the same in any language, be it java, php, etc. Another option may be to create a FULLTEXT index over the table and see if that builds your keywords as you expect.

phprockz

9:15 am on Apr 4, 2006 (gmt 0)

10+ Year Member



can u please show demo code for doing so.

scriptmasterdel

11:57 am on Apr 4, 2006 (gmt 0)

10+ Year Member



Create an array of words, create an array of selected words, then create a function to validate if the selected words are in the line of text you wish to select the word from.

<?php
$selected = "best disscussion forums";

$var = "WW is one of the best disscussion forums in world";

$sel_arr = explode(" ",$selected);
$words = explode(" ",$var);

$all = count($words)-1;

function inSelected($word,$sel)
{
if (in_array($word,$sel))
{
return $word.',';
}
}

foreach($words as $key => $word)
{
echo inSelected($word,$sel_arr);
}
?>

phprockz

4:57 pm on Apr 4, 2006 (gmt 0)

10+ Year Member



i dont want to take selected words from text ....i just need split the text with commas excluding words less then 4 characters and use them for meta keywords....thanks to everyone

orion_rus

5:49 pm on Apr 4, 2006 (gmt 0)

10+ Year Member



$array=explode(" ",$text);
foreach ($array as $key=>$value)
{
if (strlen($value)<4) unset($array[$key]);
}
$texttooutput=implode(",",$array);
echo $texttooutput

i hope it helps