Top

simple META desc & keywords generator


PHP Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  4.0 (of 1 scores)
Date Added  Apr 08, 2007
Last Updated  Jul 29, 2007
Tags  decsription  generator  keywords  meta 

Introduction

A simple generator that reads from a file of your choosing (ie. blog) and outputs the contents into tidily formated META tags.

1. Copy snippet and save to meta.php
2. First line of the snippet set value $file to the path of the file you wish to read from and save.
3. Upload to public directory.
4.simply add the following to the head element of every page you want the META to appear on.

Code:
<?php include("meta.php") ?>




Grab the Code

<?php
//set the path to the file you want to read from below.
 
$file = "test.txt"; 
 
//========================================
//do not alter from here.
 
 
$file_in = fopen($file,"r");
$file_out = fopen("meta-content.php","w");
$size = filesize($file) + 1;
 
$html = fread($file_in,$size);
$content = strip_tags($html);
 
fwrite($file_out,"<META Name="description" content="" . $content . "">n");
fwrite($file_out,"<META Name="keywords" Content="");
 
//filter $content.
 
 
$keyword_arr = explode(" ",$content);
foreach($keyword_arr as $value)
{
$n = strlen($value);
if($n > 4)
{
$strip_arr = array(",",".",";",":");
$keyword = str_replace($strip_arr,"",$value);
fwrite($file_out,$keyword . ",");
}
}
fwrite($file_out,"">n");
fclose($file_out);
fclose($file_in);
include('meta-content.php');
?>
 
 

Comments

  (3)  RSS
Hawkee
Comments: 1,039
 
PHP Snippet:  simple META desc & keywords generator
Posted on Apr 9, 2007 3:54 am
Interesting snippet. Might be nicer to take the meta tags from a database and include a meta tag editor that writes to the database.
sanity-saver
Comments: 1
 
PHP Snippet:  simple META desc & keywords generator
Posted on Apr 9, 2007 5:08 am
cool idea, will have a go at doing that, thanx for the input :)
juado
Comments: 6
 
PHP Snippet:  simple META desc & keywords generator
Posted on Feb 15, 2009 10:59 am
Could you post an example file of this?

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom