What is keyword density and how to create a script in PHP?

I am working on a project where I need to find out the keyword density of a page based on the URL of this page. I searched a lot in googled, but no help and scripts were found, I found a paid tool http://www.selfseo.com/store/_catalog/php_scripts/_keyword_density_checker_php_script

But I don’t know what the “Page density” keyword really means? and also please tell me how we can create a PHP script that will display the density of keywords on a web page.

thanks

+6
php keyword seo
source share
5 answers

Keyword Density is simply the frequency at which a word occurs as a percentage of the total number of words. The following PHP code will print the density of each word in a string, $str . It shows that keyword density is not a complicated calculation, it can be done in a few lines of PHP:

 <?php $str = "I am working on a project where I have to find out the keyword density of the page on the basis of URL of that page. But I am not aware actually what \"keyword Density of a page\" actually means? and also please tell me how can we create a PHP  which will fetch the keyword density of a web page."; // str_word_count($str,1) - returns an array containing all the words found inside the string $words = str_word_count(strtolower($str),1); $numWords = count($words); // array_count_values() returns an array using the values of the input array as keys and their frequency in input as values. $word_count = (array_count_values($words)); arsort($word_count); foreach ($word_count as $key=>$val) { echo "$key = $val. Density: ".number_format(($val/$numWords)*100)."%<br/>\n"; } ?> 

Output Example:

 of = 5. Density: 8% a = 4. Density: 7% density = 3. Density: 5% page = 3. Density: 5% ... 

To get the contents of a webpage, you can use file_get_contents (or cURL ). For example, the following PHP code lists all keywords above 1% density on this web page:

 <?php $str = strip_tags(file_get_contents("http://stackoverflow.com/questions/819166")); $words = str_word_count(strtolower($str),1); $word_count = array_count_values($words); foreach ($word_count as $key=>$val) { $density = ($val/count($words))*100; if ($density > 1) echo "$key - COUNT: $val, DENSITY: ".number_format($density,2)."%<br/>\n"; } ?> 

Hope this helps.

+23
source share

Or you can try the following: http://code.eyecatch-up.de/?p=155
Update: Moved the class to http://code.google.com/p/php-class-keyword-density-check/

 <?php include 'class/class.keywordDensity.php'; // Include class $obj = new KD(); // New instance $obj->domain = 'http://code.eyecatch-up.de'; // Define Domain print_r ($obj->result()); ?> 

The above returns the code:

 Array ( [0] => Array ( [total words] => 231 ) [1] => Array ( [keyword] => display [count] => 14 [percent] => 6.06 ) and so on... 

works with local and remote files.

+5
source share

Keyword density approximately:

(total number of keywords per page) / (total number of other keywords)

+2
source share

Keyword density simply means the percentage that keywords appear in the content and the rest of the text. All in all, this is also a pretty useless metric for SEO. I would not create a script for it, since you would be better off focusing on other metrics. You may find this link helpful.

+1
source share

If the given keyword is “elephant walks”, keyword density will be how often the term “elephant walks” appears on any given web page in relation to other text. As VirtuosiMedia said, this is (generally) useless information.

To measure this, you must remove all tags from the text, count the words, keeping track of how often the keywords appear.

At this point, you will find out that xx.xx% of all words in this text are keywords. xx.xx% of the time, the keyword (s) are used next to each other, so my keyword density for "elephant walks" is xx

Again, the only reason this is useful is to demonstrate the correspondence of templates and string functions in php.

0
source share

All Articles