Author Topic: A quick question  (Read 962 times)

Offline toxin

  • Level 21
  • *
  • Posts: 231
  • Reputation: +4/-2
    • View Profile
    • Encore Montreal
A quick question
« on: November 13, 2008, 04:44:51 AM »
I am still learning the basics and was wondering  if this was a bad way to code. I am placing my html in a php function like so.
Code: [Select]
<?php
//this function starts all pages
function html_start($page_name)
{
session_start();
//header('Content-Type: text/html; charset=UTF-8');
$doct="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"

$docs="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"// In use
$site_name="Site Name";
$keyword1="PBBG";
$keyword2="roleplaying game";
$keyword3="war game";
$keyword4="strategy game";
$keyword5="fun";
$stylesheet="style.css";
$favicon="favicon.png";
$author ="You";

$copyright ="Copyrite";
echo 
$docs 
"<html>
<head>
            <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" >

            <meta name=\"author\" content=\"
$author\">

            <meta name=\"copyright\" content=\"
$copyright \">

            <meta name=\"description\" content=\"
$description.\">
            <meta name=\"keywords\" content=\" 
$keyword1,$keyword2,$keyword3,$keyword4,$keyword5 \" >

            <link rel=\"icon\" type=\"image/png\" href=\"
$favicon\">

            <link rel=\"stylesheet\" type=\"text/css\" href=\"
$stylesheet\" >
<title>
$page_name - $site_name</title>
</head>
<body>"
;
}
function 
html_end()
{
echo"</body>
</html>"
;
}
?>

I than use it on all pages
Code: [Select]
<?php
 
include('above.php');

html_start($page="Index");

// Other site stuff goes here


html_end();

?>

« Last Edit: November 13, 2008, 04:46:25 AM by toxin »

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: A quick question
« Reply #1 on: November 13, 2008, 04:53:04 AM »
Looks OK.

I would make two separate HTML headers (description, metatags, etc are needed for search robots only, so no need for them in registered user areas only). Also all keywords in one variable (no real need to make them separate).

Offline toxin

  • Level 21
  • *
  • Posts: 231
  • Reputation: +4/-2
    • View Profile
    • Encore Montreal
Re: A quick question
« Reply #2 on: November 13, 2008, 04:56:54 AM »
Thank you for the quick reply.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: A quick question
« Reply #3 on: November 13, 2008, 05:00:42 AM »
Quick question, quick reply :D

Offline Tribal

  • Level 22
  • *
  • Posts: 256
  • Reputation: +1/-1
    • View Profile
Re: A quick question
« Reply #4 on: November 14, 2008, 11:16:19 AM »
All looks great. One thing though: Apparently PHP prefers it if you use single quotes 'text' instead of "text". If you did it that way, you wouldn't need to do "herf=\"this\">".

However, I think that is just being picky

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: A quick question
« Reply #5 on: November 14, 2008, 11:34:16 AM »
Using double quotes means you can use variables without having to concatenate it on separately.

So, this would work:
Code: [Select]
echo "Hello $username!";
But this wouldn't:
Code: [Select]
echo 'Hello $username!';
If you use single quotes and you want to use variables as well, you need to do something like this:
Code: [Select]
echo 'Hello ' . $username . '!';
//or, slightly faster:
echo 'Hello ', $username, '!';

Using single quotes is a bit faster than double quotes because PHP doesn't need to look through the quoted strings to see if there are any variables.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal