HTML
HTML or Hypertext Mark-up Language is the basis used for nearly every web page on the internet. At it's core it's simple plain text that identifies or "Marks" sections of a document. Depending on the browser you are using you can view the HTML used to generate this page by clicking "View" >> "Page source" or similar. This may look complicated the first time you look at it but it's really not. The most basic HTML document might look something like this:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
- The Doctype
The very first line declares the document type, different doctypes use different specifications. As HTML has evolved the specifications of how it's used has changed. Its important the browser knows what specification you are using, more importantly there are different variances in how a browser will display different document types.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- Start and Ending HTML Tags
An HTML tag defines the content inside in it. In almost all cases we have a start and ending tag. For example we have a start tag such as which says we're starting a new paragraph. The text following it would be the content displayed to the person viewing it, in this case Hello World!. The end tag simply says our paragraph is finished.Code: Select all
<p>Hello World!</p>
- The , and Tags
These are three special tags that should be present in every HTML document and only be used once.- - This will always follow the doctype declaration, we're simply telling the browser the HTML begins here. The ending tag will always be the last tag to close the document out.
- - The head tag contains information about the document, externally linked documents and other things. In our example code we've used the tag. This is not displayed in the browser page but instead on the title bar. This would also be used by search engines as the title when they display them.
- - This is the meat of the document, this contains the markup for what will be displayed.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<p><img src="http://www.yourdomain.com/somefolder/someimage.jpg">Hello World!</p>
</body>
</html>
For more in depth information on HTML markup and reference there is an excellent tutorial provided here:
http://www.w3schools.com/html/DEFAULT.asp
CSS
CSS or Cascading Style Sheets is used to format HTML, it can set font sizes and types. colors, positioning, sizes etc. This formatting can be placed inside the head tags, directly in the HTML or what I'm going to focus on in an external document. The trouble with using either of the first two is they are very hard to manage as a site evolves and really negate the benefits of using CSS. For example let's say we have a paragraph on a page and directly in the HTML we set the font color. We can do this by incorporating the style attribute in the p tag:
Code: Select all
<p style="color:#FF0000;">Hello World! I'm a different color!</p>
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" type="text/css" href="http://mydomain.com/mystylesheet.css">
</head>
<body>
<p class="highlight">Hello World! I'm a different color!</p>
</body>
</html>
Code: Select all
.highlight
{
color: #FF0000;
}
The reason it's called "Cascading" is because formatting can cascade:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" type="text/css" href="http://mydomain.com/mystylesheet.css">
</head>
<body>
<p>Hello World! I'm the default color!</p>
<p class="highlight">Hello World! I'm a different color!</p>
</body>
</html>
Code: Select all
p
{
color: #0000BF;
}
.highlight
{
color: #FF0000;
}
There's excellent tutorial here on CSS and references: http://www.w3schools.com/css/default.asp
PHP
PHP or Hypertext Preprocessor is a server side programming language specifically designed for web pages. It can be used for an infinite amount of things you might want to do with a page before it is sent from the server to the client. This forum for example uses PHP and a MySql backend for data storage. The page you are viewing now does not exist as would the static HTML files previously discussed. When a client makes a request for a forum page a PHP file is executed on the server, it gathers all the information from the database and generates the file on the fly. All within a fraction of a second.
Generally speaking HTML and PHP should be kept separate however doing that is really getting into some very advanced subjects. Instead I'll be using some basic examples here of how we can use PHP and static HTML together. In the following example I'll use the echo and PHP date function:
Note: the file needs to be saved with a .php extension for this to work. If you save it as .html the server will simply output the text.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<p>Hello World! Today is: <?php echo date('l jS \of F Y h:i:s A'); ?></p>
</body>
</html>
Because this code is dynamic the output sent to the clinet requesting the page will change every time the page is loaded outputting the current date and time. Learning PHP (or other server side language) is really the holy grail because again it presents infinite possibilities. There's thousands of functions like the date function and if the function doesn't exist you can make your own. I'll cover one more function and probably the most widely used one which is the include function. This would also be the most useful for those building their first web pages.Hello World! Today is: Friday 10th of July 2009 10:36:46 AM
We may have sections of page that need to be the same thing on every page of a site, for example we might have a navigation menu. If we hard code this into every page like the example provided above with the color in the CSS we would have to change this in every document that we have. Again it becomes unmanageable especially as a site grows. You can avoid this by including a file.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<?php
include($_SERVER['DOCUMENT_ROOT'] . '/includes/navigation.php');
?>
<p>Hello World!</p>
</body>
</html>
Code: Select all
($_SERVER['DOCUMENT_ROOT'] . '/includes/navigation.php')
This is a server variable that will point to the root of your domain, what's important about using it is that it provides an absolute path to where the file is we want to use. You can use this include in any file no matter what folder it resides in.
.
The period simply means append the next value
'/includes/navigation.php'
Where the file resides relative to your domain root.
So providing we have a file that would be located at yourdomain.com/includes/navigation.php it will be included in this document. The contents of navigation.php might havea structure like this:
Code: Select all
<a href="http://www.yourdomain.com/home.php">
<a href="http://www.yourdomain.com/products.php">
<a href="http://www.yourdomain.com/aboutus.php">
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<a href="http://www.yourdomain.com/home.php">Home</a>
<a href="http://www.yourdomain.com/products.php">Products</a>
<a href="http://www.yourdomain.com/aboutus.php">About Us</a>
<p>Hello World!</p>
</body>
</html>
For more information on PHP you can start with the PHP manual. This is provided online and there is a download version. Probably the best part of the manual is that is in a forum type format. At the bottom of each page you will find user provided examples of how to use the functions beyond what the official manual provides. There is also plenty of books and other material available. The internet is an endless resource as PHP is so widely used.
MySql
MySql is database and the most widely used for web pages. It can be integrated with PHP to store and retrieve data it' really as simple as that. A simple example would be an address book. More advanced examples would be this forum or an ecommerce site. I not going to go into more detail as this is some really advanced stuff but there is an excellent tutorial available here for creating an address book.
A Word of Caution
PHP and Mysql are powerful tools and that can be used against you from hackers. It is important that you learn about security before implementing it. The example I provided for using the include or date functions are not problematic but the address book tutorial should NEVER be used on a live site as it is written. It presents so many vulnerabilities it's a joke. Most notably there is no validation of the input which can lead to SQL Injection for starters.
Conclusion
I hope this was helpful, again this tutorial is meant to give some basic knowledge on what these things are and how they can be used. Most companies employ many people that specialize in certain areas from graphic design, HTML to programming. Ultimately the goal of anyone that wishes to travel this road is to understand how all these things combine. The key to manageable web sites and future upgrades is separation of all these components: Markup (HTML), Formatting(CSS), Programming(PHP) and Data(MySqL). By separating them you have created individual components that can be manipulated independent of the other. Granted total separation is not possible for those starting out and I wouldn't even begin to suggest it to the novice as you will end up beating your head against the wall. What you will want to do is work towards that goal.