Tuesday, September 25, 2007

PHP Function: Keyword Extract

This is a great little php utility function is great for bloggers or for anyone looking to increase the keyword density on a site. The keyword extract function searches through a text string filtering out punctuation and common words to return a list of your most commonly used words. Links are then generated to search for these keyword possibilities on Google and to get keyword suggestions from Wordpot.

let's go deeply and explore this function:
  1. download this zip file that contain the script.
  2. you can edit it with any PHP editor you want, for me i use notepad++ or PHP designer 2007.
  3. open the file with the editor:
  4. you will find a comment block telling you how to use this script. for us we will talk about how it works.
  5. the name of our function is "keyword_extract" it takes a variable $text that contain the text you want to extract keywords from it.
  6. First line is used to convert the text lowercase state.
  7. the 2 next lines declare a string that contain all punctuations and explode them using the explode function.
  8. a foreach loop used to replace each punctuation exploded before with a space character so it will not affect the result.
  9. declare a $commonWords variable that contain all the common words like "that,this,.." that we will not use in keywords.
  10. than a block of code used to compare the words available in the text to the common words if it's one of it it will not be counted and will be dumped. if it's not a common word it will be counted.
  11. each word that is counted more than 3 times, it will be used as a keyword, in the $keyword array.
  12. from line 89 to line 97:
    1. first line declare an array and give it array_count_values($keywords) that will take a count for each word in the keywords array.
    2. arsort($keywords): will sort the array with the index next to it. (count)
    3. foreach loop will output the result in a clear format. each keyword repeated more than 3 times, will be counted as keyword.
    4. the output give you the ability to show each keyword how much is repeated in GOOGLE and wordpot.
at the end there is an example you need to comment it in so you can use the function.

so be happy and enjoy the script :)

download here
http://www.ziddu.com/download/3537305/keyword_extract.zip.html


Digg!

6 comments:

Raghed said...

Hi i thanks PHP-mag.net for taking this article and publishing it at there website and magazine.:)

you can view it here

Anonymous said...

Is there any where to download this function as it seems to have been deleted from those sites?

Raghed said...

sorry for this inconvinience i have just edited the links:
you can downloaded from megaupload:
http://www.megaupload.com/?d=8GW418FZ

Anonymous said...

Nice blog. Thats all.

Anonymous said...
This comment has been removed by a blog administrator.
Fid"s said...

nice information bro...
thanks