Location: PHPKode > scripts > Auto Keyword META Tag Generator > keywordgen.php
<?php

//    PHP Auto Keyword Generation Script v0.4
//    Copyright (C) 2001 Chris Green - Webcreationz
//    Web   : http://www.webcreationz.co.uk
//    Email : hide@address.com
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

//    The script is simple and is not perfect, it makes mistakes
//    when generating the keyword string which I will fix in releases in 
//    the near future.
//    There is not much in the way of documentation, but as I say the script is
//    simple. One point I will make is that the parsing element of this script
//    takes an array as its argument. In this case always of one element.
//    The reason I developed it like this, is to enable to auto generation of
//    keywords from a database derived array of descriptive information which
//    will be used in a site I am planning.

//    The php file commonwords.php is an variable assignment which contains
//    a space delimited string of all words which should be excluded from
//    the parsing routine. This list is by no means complete at the moment.

if (!$sitecontents) {
$pagecontents = <<<EOF
<h1>Webcreationz - Auto Generate a Keyword String</h1>
Here is a simple utility to allow you to generate a keyword string from the contents of your webpage. Just cut and paste the contents of your site into the following text box and click submit.<p>

From the textual contents of the site a frequency of keywords in your site will be generated, pulling out 15 one word keywords, four 2 words keywords and one 3 work keyword string. Some common words are excluded from this analysis, but please do not take the results as a perfect solution, some tinkering both with the page content, and the generated keyword string will be required to give you a perfect keyword string. This process is intended more to allow you to see what keywords are most common in your site text and to see if these match the kinds of keywords you want to be targetted within the search engines.<p>

Obviously the more text provided, the better the analysis that will result.<p>

<form method=post action="$PHP_SELF" name=form>
<table border=0 cellspacing=10 cellpadding=0>
<tr><td>Site Contents:</td><td><textarea name=sitecontents rows=10 cols=27 wrap></textarea></td></tr>
<tr><td>&nbsp;</td><td><input type=submit value=Go></td></tr>
</table>
</form>

EOF;

} else {

$parsearray[] = $sitecontents;
$parsestring = "z ".strtolower(join($parsearray," "))." y";
$parsestring = str_replace (",", "", $parsestring);
$parsestring = str_replace ("\n", "", $parsestring);
$parsestring = str_replace (")", "", $parsestring);
$parsestring = str_replace ("(", "", $parsestring);
$parsestring = str_replace (".", "", $parsestring);
$parsestring = str_replace ("'", "", $parsestring);
$parsestring = str_replace ('"', "", $parsestring);

require "commonwords.php";
$commonarray = split(" ",$commonwords);

for ($i=0; $i<count($commonarray); $i++) {
   $parsestring = str_replace (" ".$commonarray[$i]." ", " ", $parsestring);
}

$parsestring = str_replace ("  ", " ", $parsestring);
$parsestring = str_replace ("  ", " ", $parsestring);
$parsestring = str_replace ("  ", " ", $parsestring);

$wordsarray = split(" ",$parsestring);

for ($i=0; $i<count($wordsarray); $i++) {
   $word = $wordsarray[$i];
   if ($freqarray[$word]) {
       $freqarray[$word] += 1;
   } else {
       $freqarray[$word]=1;
   }
}


arsort($freqarray);

$i=0;
while (list($key, $val) = each($freqarray)) {    
   $i++;
   $freqall[$key] = $val;
   if ($i==15) {
      break;
   }
} 

for ($i=0; $i<count($wordsarray)-1; $i++) {
   $j = $i+1;
   $word2 = $wordsarray[$i]." ".$wordsarray[$j];
   if ($freqarray2[$word2]) {
       $freqarray2[$word2] += 1;
   } else {
       $freqarray2[$word2]=1;
   }
}

arsort($freqarray2);

$i=0;
while (list($key, $val) = each($freqarray2)) {    
   $i++;
   $freqall[$key] = $val;
   if ($i==4) {
      break;
   }
} 

for ($i=0; $i<count($wordsarray)-2; $i++) {
   $j = $i+1;
   $word3 = $wordsarray[$i]." ".$wordsarray[$j]." ".$wordsarray[$j+1];
   if ($freqarray3[$word3]) {
       $freqarray3[$word3] += 1;
   } else {
       $freqarray3[$word3]=1;
   }
}

arsort($freqarray3);

$i=0;
while (list($key, $val) = each($freqarray3)) {    
   $i++;
   $freqall[$key] = $val;
   if ($i==1) {
      break;
   }
} 

arsort($freqall);

$pagecontents = "<h1>Webcreationz - Generate a Keyword String Frequency Results</h1>";

while (list($key, $val) = each($freqall)) {    
   $pagecontents .= "$key => $val<br>";
   $keys .= $key.", ";
} 

chop($keys);

$pagecontents .= "<hr><p>Meta Key = $keys";


}


?>
Return current item: Auto Keyword META Tag Generator