User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 403,516 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,853 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 467 | Replies: 4
Reply
Join Date: Jun 2008
Posts: 2
Reputation: phpmine is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
phpmine phpmine is offline Offline
Newbie Poster

Meta Keyword Generator

  #1  
Jun 29th, 2008
Hello you PHP Community! I am looking to make an automatic meta keyword generator based on an array of phrases. It is more my site that is under construction, PHPMine. Go to the "Q and A" section and you'll see a series of questions there, five in total. right now the system simply grabs all the words there, filters though common words, and then spits out the words as keywords. I would like some advice on how to set it up in this way:
  • puts all the words in an array and counts their frequency
  • creates an array of two words phrases and counts their frequency
  • does the same for 3 word phrases
  • spits out the top 25 keywords from the array generated

maybe someone has already cooked up this nasty script. thanks in advance guys!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 601
Reputation: R0bb0b is on a distinguished road 
Rep Power: 2
Solved Threads: 53
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Master Poster

Re: Meta Keyword Generator

  #2  
Jun 29th, 2008
This is how I would generate those arrays
  1. //$keywordsarray is the array that contains said keywords
  2.  
  3. $twowordphrases = array();
  4. //generate two word phrases
  5. for($i = 0; $i < count($keywordsarray); $i += 2)
  6. {
  7. if(isset($keywordsarray[$i + 1]))
  8. {
  9. $twowordphrases[] = $keywordsarray[$i] . " " . $keywordsarray[$i + 1];
  10. }
  11. }
  12.  
  13. $threewordphrases = array();
  14. //generate three word phrases
  15. for($i = 0; $i < count($keywordsarray); $i += 3)
  16. {
  17. if(isset($keywordsarray[$i + 2]))
  18. {
  19. $threewordphrases[] = $keywordsarray[$i] . " " . $keywordsarray[$i + 1] . " " . $keywordsarray[$i + 2];
  20. }
  21. }
Last edited by R0bb0b : Jun 29th, 2008 at 4:27 pm.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
Reply With Quote  
Join Date: Jun 2008
Posts: 2
Reputation: phpmine is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
phpmine phpmine is offline Offline
Newbie Poster

Re: Meta Keyword Generator

  #3  
Jun 29th, 2008
ah i see and now i cycle through the array and see how many times that phrase comes up right? AWESOME! I think i was trying to do this all through one pass but I'll have to create 4 loops, one that create the phrases ( the snippet you created) and then I'll have to go through each and count the number of times the phrase is found. right?
Reply With Quote  
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 601
Reputation: R0bb0b is on a distinguished road 
Rep Power: 2
Solved Threads: 53
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Master Poster

Re: Meta Keyword Generator

  #4  
Jun 29th, 2008
Right, you just cycle through the two and three word arrays just like you do the one word array.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
Reply With Quote  
Join Date: Sep 2005
Posts: 678
Reputation: digital-ether has a spectacular aura about digital-ether has a spectacular aura about 
Rep Power: 5
Solved Threads: 39
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Re: Meta Keyword Generator

  #5  
Jul 1st, 2008
Originally Posted by R0bb0b View Post
This is how I would generate those arrays
  1. //$keywordsarray is the array that contains said keywords
  2.  
  3. $twowordphrases = array();
  4. //generate two word phrases
  5. for($i = 0; $i < count($keywordsarray); $i += 2)
  6. {
  7. if(isset($keywordsarray[$i + 1]))
  8. {
  9. $twowordphrases[] = $keywordsarray[$i] . " " . $keywordsarray[$i + 1];
  10. }
  11. }
  12.  
  13. $threewordphrases = array();
  14. //generate three word phrases
  15. for($i = 0; $i < count($keywordsarray); $i += 3)
  16. {
  17. if(isset($keywordsarray[$i + 2]))
  18. {
  19. $threewordphrases[] = $keywordsarray[$i] . " " . $keywordsarray[$i + 1] . " " . $keywordsarray[$i + 2];
  20. }
  21. }


I wouldn't jump 2, and 3 words though. Just have one loop, and then take 1,2,3 words from the current word and put them into lists. That way you get each possible phrase. The current misses those that don't start with multiples of 2 and 3.

Probably good to also discard any keyword phrase that includes common words, or words less then or equal to 2 maybe 3 chars.

2 and 3 word phrases won't work so well unless you have a large body of text to compare to so you'd probably want to take your phrases to your database and do the comparison in mysql on an index for your whole site. I know its intensive, but it is worth it if you cache well.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 1:05 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC