By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

An Introduction to PHP

This Tutorial gets you started with PHP Programming.

Edited: 2014-12-28 04:25

PHP is a server-side programming language, which is used to preprocess data such as:

  1. text
  2. html
  3. css

Note. PHP is not a replacement for html or css, instead it is used together, to create "dynamic" websites. It is also used to make calculations, and take decisions if a given condition is met.

How it works

You either need your own server such as Apache, with php installed. Or a host which has support for PHP on their server.

I would suggest that beginners simply buy a domain name, and some hosting space, an example of such a host would be one.com.

Your First Page

Most examples will start out with the build-in function called "echo", as will this. Lets start by outputting some text to the browser, using echo.

<!DOCTYPE html>
<html lang="en">

  <head>
    <!--This is a HTML comment-->
    <title>My first Website</title>
  </head>

  <body>
<?php
  echo '<p>My first Website.</p>';
?>
    <!--This is a HTML comment-->
  </body>

</html>

As seen in the above example, we start by telling the server that we are going to write php. Every server which has support for php understand, "<?php" as start tag, and "?>" as end tag. You can also use the echo function to output the whole page, as seen below.

<?php
  echo '<!DOCTYPE html>
<html lang="en">

  <head>
    <!--This is a HTML comment-->
  <title>My first Website</title>
  </head>

  <body>
    <p>My first Website.</p>
    
  </body>

</html>';
?>

The above isn't really useful, so lets start using php for some useful tasks in the next few tutorials.

Past: An Introduction to HTML Next: Paragraphs and Headings in HTML