Forum Moderators: coopster
echo "
<META name=\"description\" content=\"".$_GET['description']."\">";
with the url being something like this:
[yoursite.com?description=homepage...]
PS: Thanks, again! :)
"Apache: has a special rewrite module that allows you to translate URL's containing query strings into URL addresses that search engine spiders can follow. The module, mod_rewrite, isn't automatically installed with Apache software. Check with your Web host or administrator and see if it's available on your server."
[edited by: jatar_k at 4:25 pm (utc) on May 18, 2006]
[edit reason] url removed [/edit]
using query strings is still not the best thing in regards to search engines. Stay away from them all together if you can but if necessary use mod_rewrite to make urls look static.
Try this from the Apache Forum Library [webmasterworld.com]
Changing Dynamic URLs to Static URLs [webmasterworld.com]
<?// Simple Set of SEO Related Functions
// seo_fns.php
function seo_create_title($str, $length = 70) {
// Strip HTML and Truncate to create a title, Google truncates Titles to 40 characters.
$title = truncate_string(seo_simple_strip_tags($str), $length);
if (strlen($str) > strlen($title)) {
$title .= "...";
}
return $title;
}
function seo_create_meta_description($str, $length = 120) {
// Strip HTML and Truncate to create a META description, Google doesn't care about META tags.
$meta_description = truncate_string(seo_simple_strip_tags($str), $length);
if (strlen($str) > strlen($meta_description)) {
$meta_description .= "...";
}
return $meta_description;
}
function seo_create_meta_keywords($str, $length = 200) {
// Strip HTML and Truncate to create a META keywords, Google doesn't care about META tags.
$exclude = array('description','save','$ave','month!','year!','hundreds','dollars','per','month','year',
'and','or','but','at','in','on','to','from','is','a','an','am','for','of','the');
$splitstr = @explode(" ", truncate_string(seo_simple_strip_tags(str_replace(array(",",".")," ", $str)), $length));
$new_splitstr = array();
foreach ($splitstr as $spstr) {
if (strlen($spstr) > 2 &&!(in_array(strtolower($spstr), $new_splitstr)) &&!(in_array(strtolower($spstr), $exclude))) {
$new_splitstr[] = strtolower($spstr);
}
}
return @implode(", ", $new_splitstr);
}
function seo_simple_strip_tags($str)
// Simple Strip HTML Tags function for seo functions above.
{
$untagged = "";
$skippingtag = false;
for ($i = 0; $i < strlen($str); $i++) {
if (!$skippingtag) {
if ($str[$i] == "<") {
$skippingtag = true;
} else {
if ($str[$i]==" " ¦¦ $str[$i]=="\n" ¦¦ $str[$i]=="\r" ¦¦ $str[$i]=="\t") {
$untagged .= " ";
} else {
$untagged .= $str[$i];
}
}
} else {
if ($str[$i] == ">") {
$untagged .= " ";
$skippingtag = false;
}
}
}
$untagged = preg_replace("/[\n\r\t\s ]+/i", " ", $untagged); // remove multiple spaces, returns, tabs, etc.
if (substr($untagged,-1) == ' ') { $untagged = substr($untagged,0,strlen($untagged)-1); } // remove space from end of string
if (substr($untagged,0,1) == ' ') { $untagged = substr($untagged,1,strlen($untagged)-1); } // remove space from start of string
if (substr($untagged,0,12) == 'DESCRIPTION ') { $untagged = substr($untagged,12,strlen($untagged)-1); } // remove 'DESCRIPTION ' from start of string
return $untagged;
}
function truncate_string($string, $length = 70)
// This function will truncate a string to a specified length.
{
if (strlen($string) > $length) {
$split = preg_split("/\n/", wordwrap($string, $length));
return ($split[0]);
}
return ($string);
}
function ucfirst_title($string) {
// Split the words (\W) by delimiters, ucfirst and then recombine with delimiters.
$temp = preg_split('/(\W)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
foreach ($temp as $key=>$word) {
$temp[$key] = ucfirst(strtolower($word));
}
$new_string = join ('', $temp);
// Do the Search and Replacements on the $new_string.
$search = array (' And ',' Or ',' But ',' At ',' In ',' On ',' To ',' From ',' Is ',' A ',' An ',' Am ',' For ',' Of ',' The ',"'S", 'Ac/');
$replace = array (' and ',' or ',' but ',' at ',' in ',' on ',' to ',' from ',' is ',' a ',' an ',' am ',' for ',' of ',' the ',"'s", 'AC/');
$new_string = str_replace($search, $replace, $new_string);
// Several Special Replacements ('s, McPherson, McBain, etc.) on the $new_string.
$new_string = preg_replace("/Mc([a-z]{3,})/e", "\"Mc\".ucfirst(\"$1\")", $new_string);
// Another Strange Replacement (example: "Pure-Breed Dogs: the Breeds and Standards") on the $new_string.
$new_string = preg_replace("/([:;])\s+([a-zA-Z]+)/e", "\"$1\".\" \".ucfirst(\"$2\")", $new_string);
// If this is a very low string ( > 60 char) then do some more replacements.
if (strlen($new_string > 60)) {
$search = array (" With "," That ");
$replace = array (" with "," that ");
$new_string = str_replace($search, $replace, $new_string);
}
return ($new_string);
}
function wordwrap_excluding_html($str, $cols = 30, $cut = "­")
// This is a simple HTML-excluding, max-column/character, word wrap function!
// This function will split a word, that is longer that $cols and is outside
// any HTML tags, by the string $cut. Lines with whitespace in them are ok, only
// single words over $cols length are split. (­ = safe-hyphen)
{
$len = strlen($str);
$tag = 0;
for ($i = 0; $i < $len; $i++) {
$chr = $str[$i];
if ($chr == '<') {
$tag++;
} elseif ($chr == '>') {
$tag--;
} elseif ((!$tag) && ($chr==" " ¦¦ $chr=="\n" ¦¦ $chr=="\r" ¦¦ $chr=="\t")) {
$wordlen = 0;
} elseif (!$tag) {
$wordlen++;
}
if ((!$tag) && ($wordlen) && (!($wordlen % $cols))) {
$chr .= $cut;
}
$result .= $chr;
}
return $result;
}
function truncate_string_excluding_html($str, $len = 150)
// This function will truncate a string to a specified length
// "excluding" any HTML tags in the length calculation.
// Split on HTML delimiters, count and then recombine with delimiters.
{
$wordlen = 0; // Total text length.
$resultlen = 0; // Total length of HTML and text.
$len_exceeded = false;
$cnt = 0;
$splitstr = array (); // String split by HTML tags including delimiter.
$open_tags = array(); // Assoc. Array for Simple HTML Tags
$str = str_replace(array("\n","\r","\t"), array (" "," "," "), $str); // Replace returns/tabs with spaces
$splitstr = preg_split('/(<[^>]*>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE );
//var_dump($splitstr);
if (count($splitstr) > 0 && strlen($str) > $len) { // split
while ($wordlen <= $len && $cnt <= 200 &&!$len_exceeded) {
$part = $splitstr[$cnt];
if (preg_match('/^<[A-Za-z]{1,}/', $part)) {
$open_tags[strtolower(substr($match[0],1))]++;
} else if (preg_match('/^<\/[A-Za-z]{1,}/', $part)) {
$open_tags[strtolower(substr($match[0],2))]--;
} else if (strlen($part) > $len-$wordlen) { // truncate remaining length
$tmpsplit = explode("\n", wordwrap($part, $len-$wordlen));
$part = $tmpsplit[0]; // Define the truncated part.
$len_exceeded = true;
$wordlen += strlen($part);
} else {
$wordlen += strlen($part);
}
$result .= $part; // Add the part to the $result
$resultlen = strlen($result);
$cnt++;
}
//echo "wordlen: $wordlen, resultlen: $resultlen<br />";
//var_dump($open_tags);
// Close the open HTML Tags (Simple Tags Only!). This excludes IMG and LI tags.
foreach ($open_tags as $key=>$value) {
if ($value > 0 && $key!= "" && $key!= null && $key!= "img" && $key!= "li") {
for ($i=0; $i<$value; $i++) { $result .= "</".$key.">"; }
}
}
} else {
$result = $str;
}
return $result;
}
?>