homepage Welcome to WebmasterWorld Guest from 54.166.122.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Use Variables in a URL to Import Different META Tags?
How to change the META tags on a page with a variable in the URL
clearpixel

10+ Year Member



 
Msg#: 12930 posted 3:03 am on May 18, 2006 (gmt 0)

I've been on a roll (obsessed?) with learning how to import files and manipulate code on a page using variables in a URL, but I am now curious how I would do the same for META tags? I've been able to import actual text into the body area of a page and change the title tag, but can I import an entire META tag file into the header of a page?

 

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 12930 posted 3:46 am on May 18, 2006 (gmt 0)

I don't see a reason that you would want dynamic meta tags, but i guess if you really wanted to, you could. It is the same as all of the other posts that you have made, except you are putting it within a meta tag instead of, in your example, a title tag.

echo "
<META name=\"description\" content=\"".$_GET['description']."\">";

with the url being something like this:
[yoursite.com?description=homepage...]

clearpixel

10+ Year Member



 
Msg#: 12930 posted 6:32 am on May 18, 2006 (gmt 0)

The reason for the request is so I can create an entire page using one hard coded PHP template which can be almost entirely changed based on variables in the URL. Partly I want to be able to do this to create customized landing pages for PPC campaigns, but I am also trying to develop a standardized parking page for approx. 30 domains I own. For each domain I want to have a customized version of the same template with ads and relevant news feeds. My thinking in also controling the Meta tags was to make the pages SEO friendly as well. However, just to be sure, how will search engine spiders treat the page - if technically it is one actual page with a series of variables in the URL - will spiders follow links into the page and categorize the different URLs as different pages or will they only see the template?

PS: Thanks, again! :)

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 12930 posted 11:17 am on May 18, 2006 (gmt 0)

You can find information about that here. One particular line you should notice is:

"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]

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 12930 posted 4:47 pm on May 18, 2006 (gmt 0)

I wouldn't use variables in the url, I would use a config file or something similar to set the necessary values for each domain.

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]

jjwdesign

5+ Year Member



 
Msg#: 12930 posted 3:13 pm on May 21, 2006 (gmt 0)


<?

// 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 = "&shy;")
// 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. (&shy; = 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;
}

?>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved