MMD2 Multimedia Deign PHP

Principles of PHP

Here is a very short introduction to the principles of PHP.  PHP is an acronym for “hypertext preprocessor”. PHP is a serverside language. We use PHP in order to prepare webpages, react to user input – and (on the third semester) to interact with databases.

Many Open Source CMSs use a combination of Apache, PHP and MySQL as an “engine”.

How to write PHP code

A php file is made in a manner similar to a HTML file. You create a file and give it the surname .php. So a file name sample could be:

  • myFile.php

The file can contain other forms of code and tags such as JavaScript, CSS or HTML. In the file the php code is nested between a <? and ends with a ?>.

Variables, Strings and numbers

$a = 10; // a number
$b = “Hello World”; // a string
$c = “Ho, ho, hooo!”; // yes it’s another string
$d = “Santa Claus, says: “; // xmas is near
$combinedStrings = $d . $c; // Santa Claus, says: Ho, ho, hooo!
$e = NULL; // no value set
$f = true; // or false

A variable is defined via the $ character. In the sample code above you can see several variables.

A string starts and ends with a quotation mark as ” or ‘. If you need quotation marks inside a string they should be nested like this:

<? $foo = “<img src=’image.png’  alt=’an image’ />”; ?>

You can create HTML code via PHP – and you can show an image on a web page like this:

<? echo $foo; ?>


<? print(“$foo”); ?>


Since a variable can be a number, you can use PHP for calculations, such as:

$x = 1;
$y = 19;
echo $x + $y; // should return 20

See this page for more information about PHP and calculations.






By Per Thykjaer Jensen

Per is the WordPress expert at Business Academy Aarhus. Senior Lecturer at the Multimedia Design Programme. His background is in the Arts: MA Literature History and BA Art History. Later he added a MA in IT, interaction and Multimedia. And he is a wicked Linux user.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.