Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,574 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,874 people online right now. Registration is fast and FREE... Join Now!




Dynamic PHP Title

 
Reply to this topicStart new topic

Dynamic PHP Title

shibbycookieofdeath
3 Oct, 2008 - 11:53 PM
Post #1

New D.I.C Head
*

Joined: 23 Sep, 2007
Posts: 5


My Contributions
Hi. I'm a novice in PHP and I'm using a code for my header and I was wondering how I would add a PHP script to it so that when it calls the selected page: main.php, about.php, etc it'll show up in the title after the | symbol. See this site for example. Notice how whenever you click on the link the url bar reads http://ottoid.com/pixeldistortion/?p=portfolio then the title reads Pixel Distortion / Portfolio. I want something to add to the PHP script I already have. Thanks for any help you guys can give me! biggrin.gif

CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
$path = getcwd() . '/content';
$extension = 'php';
$default = 'main';

function showError($msg) {
  echo "<h1>Error</h1>\n";
  echo "        <span>" . $msg . "</span>\n";
}

function includeContentFile() {
  global $path, $extension, $default;
  $filename = isset($_GET['p']) ? $_GET['p'] : $default;
  if (! $filename) {
  showError('No page selected.');
  return;
}

foreach (array('.', '/', '\\') as $illegal) {
if (false !== strpos($filename, $illegal)) {
  showError('Illegal characters in page parameter.');
  return;
}
}

$fullpath = realpath(sprintf('%s/%s.%s', $path, $filename, $extension));
if (! file_exists($fullpath)) {
    showError('This page has not been created yet.');
  return;
}
  include($fullpath);
}
  include('replacePngTags.php');
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<title>BuiltNoble | The Upper Class of Webdesign™</title>

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="keywords" content="BuiltNoble.com, builtnoble.com, BuiltNoble, builtnoble, shibbycookieofdeath, shibbycookies, jleemero" />
<meta name="description" content="The Upper Class of Web Design." />
<meta name="revist-after" content="2 days" />

<link href="/builtnoblev2/resources/css/main.css" rel="stylesheet" type="text/css" media="screen" />
<script src="/builtnoblev2/resources/js/zoom.js" type="text/javascript"></script>

</head><body onload="setupZoom()">

User is offlineProfile CardPM
+Quote Post

tkulev
RE: Dynamic PHP Title
4 Oct, 2008 - 02:37 AM
Post #2

New D.I.C Head
*

Joined: 3 Oct, 2008
Posts: 13


My Contributions
It's easy. Just try something like this:
php

switch($_GET['p'])
{
case "portfolio": $myTitle="Pixel Distortion / Portfolio";
break;
case "other": $myTitle="Other Title";
break;
default: $myTitle="Default Title";
}

Put this code somewhere before title tag and print $myTitle after the "|".
User is offlineProfile CardPM
+Quote Post

pe_mitev
RE: Dynamic PHP Title
4 Oct, 2008 - 02:03 PM
Post #3

D.I.C Head
Group Icon

Joined: 28 Dec, 2007
Posts: 71


Dream Kudos: 50
My Contributions
I think that it would be better to insert the code into the block where you check if such files exists and you can still use the example of tkulev, but the parameter of the switch should be $fullpath(depending on what I saw in your code or to summarize -> the variable that is being used for the necessary page).
User is offlineProfile CardPM
+Quote Post

shibbycookieofdeath
RE: Dynamic PHP Title
4 Oct, 2008 - 09:05 PM
Post #4

New D.I.C Head
*

Joined: 23 Sep, 2007
Posts: 5


My Contributions
Thank you both! icon_up.gif

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:06AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month