Introduction to PHP

Discussion in 'Web Design & Programming' started by RHochstenbach, Mar 8, 2011.

  1. RHochstenbach

    RHochstenbach Administrator

    Likes Received:
    26
    Trophy Points:
    48
    PHP is a so-called server-side programming language. This basically means that the server renders the page instead of the web browser. This has many advantages, including (but not limited to) the following:
    • Perform calculations
    • Generate information
    • Connect and exchange information with a database
    You can't see PHP, because it only contains instructions. Instead, you integrate PHP code inside a visual markup language like HTML. Almost 99% of all PHP code is used inside HTML code.

    So quickly summarized, the server executes PHP instructions and then passes the output to the markup language in which it is integrated, like HTML. The server executes all instructions, and then passes it to the visitor's web browser as HTML code.

    To get PHP working on a server, you need to have PHP installed (and optionally, but recommended if you want to use a database: MySQL). There are numerous ways to install this, but I would suggest installing this on a Linux system like Ubuntu.

    As of writing, the latest version of PHP is version 5.

    Before you start learning PHP, you should first master the markup language in which you're going to integrate this. This will probably be HTML, so make sure you learn that first.

    Making an HTML page with PHP code
    To have PHP working properly in HTML, you should save the file with a .php extension instead of an .htm or .html extension. Otherwise the server does not know it need to pass it to PHP first.

    All PHP code needs to be wrapped into PHP tags in order for it to be run properly. This is an example of an HTML file with PHP code:
    HTML:
    <html>
    <head>
    <body>
    
    Regular HTML Code
    
    <?php
    
    PHP code
    
    ?>
    
    Regular HTML Code
    
    </body>
    </html>
    You can wrap PHP code between <?php ?> or <? ?>, although the full tag (<?php) is more compatible, so always use that.
     

Share This Page