什么是关键字密度以及如何在PHP中创建脚本?
我在一个项目中,我必须找出该网页的URL的基础上,该页的关键字密度工作。我在谷歌上搜索了很多,但是没有找到帮助和脚本,我找到了一个付费工具 但我不知道“页面关键字密度”到底是什么意思?另外,请告诉我如何创建一个PHP脚本来获取网页的关键字密度什么是关键字密度以及如何在PHP中创建脚本?,php,seo,keyword,Php,Seo,Keyword,我在一个项目中,我必须找出该网页的URL的基础上,该页的关键字密度工作。我在谷歌上搜索了很多,但是没有找到帮助和脚本,我找到了一个付费工具 但我不知道“页面关键字密度”到底是什么意思?另外,请告诉我如何创建一个PHP脚本来获取网页的关键字密度 谢谢关键字密度只是指内容中出现的关键字与文本其余部分的百分比。一般来说,这也是一个相当无用的SEO指标。我不会费心为它构建一个脚本,因为你最好专注于其他指标。您可能会发现这很有用。如果给定的关键字是“大象行走”,则关键字密度将是术语“大象行走”相对于其他文
谢谢关键字密度只是指内容中出现的关键字与文本其余部分的百分比。一般来说,这也是一个相当无用的SEO指标。我不会费心为它构建一个脚本,因为你最好专注于其他指标。您可能会发现这很有用。如果给定的关键字是“大象行走”,则关键字密度将是术语“大象行走”相对于其他文本出现在任何给定网页上的频率。正如VirtuosiMedia所说,这(大体上)是无用的信息 为了衡量它,你必须去掉文本中的所有标记,计算单词数量,同时跟踪关键字出现的频率 此时,您将知道,本文中所有单词的xx.xx%是关键字。xx.xx%的时间里,关键字彼此相邻,因此我的“大象行走”关键字密度为xx
同样,这是有用的唯一原因,是在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";
}
?>
要获取网页内容,您可以使用(或)。例如,以下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";
}
?>
我希望这有帮助。或者您可以试试这个:更新:将类重新定位到
使用本地和远程文件 谢谢你,汤姆!这很好-使用strip_标签可以用其他东西代替(阅读评论),但这很有效!这很好,但我如何使它工作,以配合2和3字短语?
<?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";
}
?>
<?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...