Clean PHP – A journey of 20 pages, starts with one line of code

Before we start

I’d like to mention that I’ve created a repository of code of what this scaffolding project has become. Lots of goodies in there. Check it out yourself here:
https://github.com/gbutiri/cleanphp

Clean and simple PHP

This page is dedicated to showing you how simple a PHP based website can be.

In the beginning…

1
<html></html>

It all started with HTML, but then things changed. The history of web development went through some amazing changes. Some were milestones, and some were simply just advances that today we couldn’t imagine how we program web pages without.

Let’s take a look at the simplest “Hello World” web site. After setting up your web server, add the following code to your index page (index.php).

1
2
3
4
5
6
7
8
<html>
    <head>
        <title>Another Hello World website</title>
    </head>
    <body>
        <p>Hello World!</p>
    </body>
</html>

You can technically just put Hello World in your page, but that’s not really standardized code. A web browser expects certain standards, like the use of tags, such as the <html>, <head>, <body>, <title>, and the <p> tag. These tags tell your browser how to render the page.

!!! Important !!! – A website is simply a collection of web pages. Each web page behaves individually of every other web page. The difference between web programming and application programming is that an application is meant to stay alive in memory the whole time from start to when the end user exists the application. A website is really a collection of applications, or pages that are only in memory and processing until the page is fully rendered.

Let’s make our page W3C compliant. You can always check to see if your site validates at http://validator.w3.org/

1
2
3
4
5
6
7
8
9
10
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Another Hello World website</title>
            <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        </head>
        <body>        
            <p>Hello World!</p>    
        </body>
    </html>

Notice that we added a DOCTYPE to tell browsers what kind of document we have. We picked 4.01 Transitional because of its flexibility to allow deprecated elements, like <font>.

We added a content type to tell the browser application that we want the character encoding to be UTF-8, or universal.

Summary

This is it. You made your very first, valid, HTML page and website. But what if you want to add some bells and whistles, or make it multiple paged website? Stand by!