HTML and PHP

Sorry, I forgot how this works…

First off, I was told on Sitepoint that the following header information would be the best way for me to code my web pages…

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>TITLE</title>
	<link type="text/css" rel="stylesheet" href="PathToStyleSheet.css">
    </head>
    <body>

    </body>
</html>

I am getting ready to create my “index.php” file, and I’m not sure if I can just paste the above code in it, or what?!

I am trying to do a test PHP page that has a registration form on it.

The web page will have both (X)HTML and PHP in it. The form and all will be in HTML and CSS, but I’ll need PHP to process the form.

So can I start off a PHP file with an HTML header and then just add the PHP code down below?

Or if a file is a .php file, does it need a PHP header?

Follow where I am confused?! :-/

Debbie

there is a concept: active pages, dynamic pages as opposed to static pages, that is involved with what you’re asking, and is not restricted to php. php is only one of the many ways to have static html content become active, dynamic, with the help of the server side technologies.

As guido alluded to earlier a .php file is essentially a .htm file with php code inside of it.

I’ll summarise quickly what normally happens.

  1. Say you have a plain vanilla html file with some optional javascript and css.

When someone points to that page on your server, the web server sends the html file back to the requestors browser and the browser processes the html, javascript and css and eventually displays your web page’s content in their browser

  1. Say you now have some php code as well in the same html file as in 1).

The file should now have a .php extension. This .php extension tells the web server that when someone points their browser to that .php file, the server should first send that php file to the php “engine” on the server. The php engine then reads through that php file line by line and ouputs any html, js,css code unaltered and processes any php code between <?php ?> tags as it comes across them. Any output from the php code is then inserted in place of the php code in the original php file. When the entire .php file has been read and processed by the php engine, the resultant output , which is now just plain html with the original js, css and output from the php code is sent back to the requestors browser and processed by the browser as in 1).

I hope this makes sense.

Yes, good one Kalon. It’s what I wanted to say, but you said it better :slight_smile:

Kalon, I think I like your explanation the best! :tup:

(Although thanks to everyone for contributing!)

My brain is starting to get it now…

Thanks,

Debbie

What? :shifty:

You don’t need a header with .php, nor do you need to optimize meta tags, titles, or anything else. Focus solely on keeping your site content fresh, and everything else takes cares of itself, by itself…

So I can think of a .php file as a large “bucket” where I can dump in HTML, CSS, Javascript, etc and I can start off with any type of HTML or XHTML header and then just insert PHP later on below the header and everything will be okay?

(If my first few lines are like the HTML header shown above, I assume you could put PHP before that, right??)

Debbie

No need for a php header. The .php extension will tell the server that the file has to be passed through the php parser before sending the data to the client (browser). Inside the php file, you can have a mix of (x)html, css, javascript, and php code. After the php code has been executed, the result will be a pure (x)html/css/js document, and that will be sent to the client.
So yes, you can start the file off with a HTML header.

Just keep your site content updated. Basically, that’s what I was saying. No need to optimize meta tags, headers, and keywords and all that stuff. Just stick to the basics…

I love that concept, and yes… basically the file is a bucket. With a .html file you can stick your HTML, CSS and JavaScript inside (though separating structure, style and behaviour is the best option, so I recommend having JavaScript in a JS file and CSS in .css files!) but if you’re pages have a .php extension you can literally embed PHP code directly into the HTML within the file and it’ll run like magic. Basically the .php is a .html with PHP able to work inside. :slight_smile: