什么是关键字密度以及如何在PHP中创建脚本?

Pra*_*ant 6 php seo keyword

我正在开发一个项目,我必须根据该页面的URL找出该页面的关键字密度.我google了很多,但没有找到任何帮助和脚本,我找到了一个付费工具http://www.selfseo.com/store/_catalog/php_scripts/_keyword_density_checker_php_script

但我实际上并不知道"关键字页面密度"究竟是什么意思?还请告诉我如何创建一个PHP脚本来获取网页的关键字密度.

谢谢

Tom*_*Tom 23

"关键字密度"只是单词出现的频率,以字总数的百分比形式给出.以下PHP代码将输出字符串中每个单词的密度$str.它表明关键字密度不是一个复杂的计算,它可以在几行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 script 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";
}
?>
Run Code Online (Sandbox Code Playgroud)

示例输出:

of = 5. Density: 8%
a = 4. Density: 7%
density = 3. Density: 5%
page = 3. Density: 5%
...
Run Code Online (Sandbox Code Playgroud)

要获取网页内容,您可以使用file_get_contents(或cURL).例如,以下PHP代码列出了此网页上密度超过1%的所有关键字:

<?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";
}
?>
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助.


ste*_*han 5

或者你可以尝试这个:http
: //code.eyecatch-up.de/?p = 155更新:将课程重新定位到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()); 
?>
Run Code Online (Sandbox Code Playgroud)

上面的代码返回:

Array
(
    [0] => Array
        (
            [total words] => 231
        )

    [1] => Array
        (
            [keyword] => display
            [count] => 14
            [percent] => 6.06
        )
and so on...
Run Code Online (Sandbox Code Playgroud)

适用于本地和远程文件.