Jump to content

keyword density of the page


runeveryday

Recommended Posts

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 how to begin? and also how can we create a PHP script which will fetch the keyword density of a web page.who can give me a train of thought.the more detail,the better.thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/194903-keyword-density-of-the-page/
Share on other sites

Use file_get_contents to get the page

then use get_meta_tags to get the keywords

then grab the body

grab the links text

break the body down to just words

count the words

loop through and count keyword occurrences in body text

count occurrences of keywords in link text

divide to get the percentage or however else you want to weigh it

 

 

HTH

Teamatomic

 

i am a newbie,the following code is i tried to do about the problem.hope anyone can help me.

the primary front code:

<form action="check.php" method="post">
Keyword:<input type="text" name="keyword" />
Website URL: <input type="text" name="url" />
<input type="check" />
</form>

 

 

 

php file:

<?php
$homepage = file_get_contents('$_POST["url"]');

$tags = get_meta_tags('$_POST["url"]');
.........

?>

 

i am sorry,i don't know how to continue. and i want to the keywords which the vistor can input.

This is from an ugly little script we use internally for SEO.

 

//define regex for preg
$b_start = '<body .*>';
$b_stop = '<\/body>';
//match the content between tags
preg_match( "/$b_start(.*)$b_stop/s", $content, $body );
// grab body text
$body=$body[0];
// get links text from body
preg_match_all('/<a .*\>(.*)<\/a>/', $body, $link_text);
$lkw=$link_text[1];
array_filter($lkw);
//strip out html
$bt=strip_tags($body);

 

 

HTH

Teamatomic

Here, here's the whole thingy. Do anything you want with it except say you own it.

Just set the url and that it.

 


$url = "put url here";

$content=file_get_contents("$url");

$start = '<title>';
$end = '<\/title>';
preg_match( "/$start(.*)$end/s", $content, $match );
$title = $match[1];


$metatagarray = get_meta_tags("$url");
$keywords = $metatagarray["keywords"];
$keywords_array=explode(",",$keywords);
$description = $metatagarray["description"];

echo "<b>URL ::</b> $url<br>";
echo "<b>Title ::</b> $title</br>";
echo "<b>Description ::</b> $description<br>";
echo "<b>Keywords ::</b> $keywords<br>";

$b_start = '<body .*>';
$b_stop = '<\/body>';
preg_match( "/$b_start(.*)$b_stop/s", $content, $body );
$body=$body[0];
$bt=strip_tags($body);
$body_word_count = count(explode(" ",$bt));

echo "<br><b>Body Word Count</b> - $body_word_count<br>";
preg_match_all('/<a .*\>(.*)<\/a>/', $body, $link_text);
$lkw=$link_text[1];
array_filter($lkw);
$kw_found=array();

foreach($keywords_array as $word)
{
$i=1;
$word=strtolower($word);

foreach($lkw as $w)
{
$w=strtolower($w);

if($word == $w)
{
$kw_found[$w]=$i;
$i++;
}
}
  }
     
echo "<p><b>Keyword Link Match</b><br>";

foreach($kw_found as $key => $value)
{
$p1 = floatval($value) / floatval($body_word_count);
$p2 = $p1 * 100;
$p=sprintf("%01.2f", $p2);

echo "$key :: $value :: $p%<br>";
}
echo "<p>";

$body_count=array();

foreach($keywords_array as $word)
{
$count = substr_count($bt,$word);
$body_count[$word]=$count;
$count=0;
}

echo "<p><b>Keyword Body Match</b><br>";

foreach($body_count as $key => $value)
{
$p1 = floatval($value) / floatval($body_word_count);
$p2 = $p1 * 100;
$p=sprintf("%01.2f", $p2);

echo "$key :: $value :: $p%<br>";
}

 

 

HTH

Teamatomic

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.