Introduction to PHP

Required Knowledge

HTML knowledge is recommendable. Click here to go to the HTML collection.

What is PHP

While PHP originally stood for Personal Home Page, it now is a recursive acronym for Hypertext Preprocessor. Read more about recursive acronyms. PHP is a server-side programming language, which means that is primary designed for Web Development. It can also be used as a general-purpose programming language, which is used to create software/applications (Other general-purpose programming languages are C++, COBOL and Python). In this collection you'll learn more about using of PHP for Web Development.

How does a server-side programming language work?

While client-side languages like HTML, CSS and JavaScript are processed in the user's web browser server-side languages are processed on a server. Let's compare client-side and server-side with an infographic:

Infographic that compares Server-side and Client-side scripting

As you can see, we need a server to make PHP work. Learn more about servers.

Purpose of PHP

PHP adds interactivity and dynamics to HTML pages. With PHP we can send emails, save data, fetch data from databases, calculate and a whole lot more!

Code editors

Before we start showing PHP code, you should make sure that you have a code editor installed on your computer. A code editor makes programming a lot easier because it highlights the syntax(the structure) and reports faults in your code. Great free code editors are Aptana Studio for Mac, Scriptly for Windows and Kate for Linux.

Structure of PHP files

PHP code is saved in simple text files. PHP commands have to be in special PHP-areas that separate PHP-code from other code (HTML, CSS etc.).

As you can see we use a basic HTML file. The PHP area starts at <?php and ends at ?>. Everything that is between these markings is interpreted by the PHP parser which is also called PHP interpreter.

You can specify multiple PHP-Areas in one file. Always make sure to end the PHP area before continuing with other content.

The echo command creates an output on the screen. When the parser is done all contents of an output appear in the resulting file. After the parsing of our script it will only contain HTML:

If you want to add dynamics to your HTML pages you should include your PHP code inside the HTML code. You can also use PHP as a basic language, which you would use to start a file. Such a file usually consists of one single PHP-area. Contents are displayed with echo and print.

Continue to part 2