Tuesday, 25. September 2007
How To Use PHP's Keyword Extract Function
PHP's 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. Raghed Edris says this is a great little php utility function is great for bloggers or for anyone looking to increase the keyword density on a site. He steps you thorugh
how to use the function:
- download this zip file that contain the script.
- you can edit it with any PHP editor you want, for me i use notepad++ or PHP designer 2007.
- open the file with the editor:
- you will find a comment block telling you how to use this script. for us we will talk about how it works.
- the name of our function is "keyword_extract" it takes a variable that contain the text you want to extract keywords from it.
- First line is used to convert the text lowercase state.
- the 2 next lines declare a string that contain all punctuations and explode them using the explode function.
- a foreach loop used to replace each punctuation exploded before with a space character so it will not affect the result.
- declare a variable that contain all the common words like "that,this,.." that we will not use in keywords.
- 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.
- each word that is counted more than 3 times, it will be used as a keyword, in the array.
- from line 89 to line 97:
- first line declare an array and give it array_count_values() that will take a count for each word in the keywords array.
- arsort(): will sort the array with the index next to it. (count)
- foreach loop will output the result in a clear format. each keyword repeated more than 3 times, will be counted as keyword.
- the output give you the ability to show each keyword how much is repeated in GOOGLE and wordpot.