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

但我实际上并不知道“关键字页面密度”是什么实际意味着?还请告诉我如何创建一个PHP脚本来获取网页的关键字密度。

由于

有帮助吗?

解决方案

“关键字密度”简单地说,单词出现的频率占单词总数的百分比。以下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";
}
?>

示例输出:

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

要获取网页内容,您可以使用 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";
}
?>

我希望这会有所帮助。

其他提示

或者你可以试试这个: 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()); 
?>

上面的代码返回:

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

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

适用于本地和远程文件。

关键字密度大致为:

(页面上出现次数关键字)/(其他关键字的总数)

关键字密度仅表示关键字在内容与文本其余部分中显示的百分比。一般来说,它对SEO来说也是一个相当无用的指标。我不打算为它构建一个脚本,因为你最好专注于其他指标。您可能会发现此参考非常有用。

如果给定的关键字是“大象行走”,则关键字密度将是术语“大象行走”的频率。出现在任何给定网页上与其他文本相关的内容。正如VirtuosiMedia所说,这是(广义上)无用的信息。

要测量它,您必须从文本中删除所有标记,计算单词,同时跟踪关键字出现的频率。

此时,您会知道,本文中所有单词的xx.xx%都是关键字。 xx.xx%的时间,关键字彼此相邻使用,因此我的关键词密度为“elephant walking”。是xx

同样,这个有用的唯一原因是在php中演示模式匹配和字符串函数。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top