2009-05-04 4 views
6

私はそのページのURLに基​​づいてページのキーワード密度を調べなければならないプロジェクトに取り組んでいます。私はたくさんのGoogle検索をしましたが、ヘルプとスクリプトは見つかりませんでした。有料ツールを見つけましたhttp://www.selfseo.com/store/_catalog/php_scripts/_keyword_density_checker_php_scriptキーワード密度とは何ですか?また、PHPでスクリプトを作成する方法は?

実際には「ページのキーワード密度」は実際にはどういう意味ですか?また、ウェブページのキーワード密度を取得するPHPスクリプトを作成するにはどうすればいいのか教えてください。

おかげ

答えて

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"; 
} 
?> 

出力例:

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

は、あなたがfile_get_contentsを使用することができ、ウェブページのコンテンツを取得するには(またはcURL)。例として、以下のPHPコードは、このWebページ上の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"; 
} 
?> 

私はこのことができます願っています。

+0

ありがとうTom!これはうまくいきました - strip_tagsを使って別のものに置き換えることができました(http://php.net/manual/en/function.strip-tags.phpのコメントを読んでください)。 – IEnumerator

+0

これはすばらしいですが、2〜3語のフレーズにマッチさせるにはどうすればいいですか? – chovy

1

キーワード密度はちょうどキーワードがテキストの残りの部分に対して、コンテンツに表示される割合を意味します。一般的に、それはSEOにとってもかなり役に立たない指標です。他の指標に集中する方が良いので、スクリプトを作成するのは気にしません。このreferenceが役に立ちます。

0

キーワードが「elephant walks」である場合、キーワード密度は、他のテキストと比較して任意のWebページに「elephant walks」という語が表示される頻度です。 VirtuosiMediaが言っているように、これは(広く)役に立たない情報です。

これを測定するには、テキストからすべてのマークアップを取り除き、そのキーワードが表示される頻度を記録しながら単語をカウントする必要があります。

この時点で、このテキストのすべての単語のxx.xx%はキーワードであることがわかります。 xx.xx%の時間の間、キーワードが互いに隣り合って使用されるため、「象の散歩」のキーワード密度はxx

です。 phpの文字列関数

1

キーワード密度はおおよそ次のとおりです。

(無回キーワードのページに登場。)は/

5

それとも、この試すことができます:ローカルとリモートのファイルと

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

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

作品:コード戻り上記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()); 
?> 

にクラスを移転: http://code.eyecatch-up.de/?p=155
更新。

関連する問題