Sponsored Links :
  • PHP

    Now it’s time to get down to the real task at hand - actually creating a working web-page using PHP. In this tutorial, I’ll show you how to create a simple web-page to demonstrate how to add a little bit of dynamic jazz to an otherwise static site.

    Mixing PHP with HTML

    I’m assuming, for this tutorial, and throughout the rest of the tutorials, that you have at least a basic knowledge of HTML - enough to be able to use simple tags such as <br/> (newline), <a>, <form> and so on. If not, why not check out any of the decent HTML tutorials around the web - Google for “HTML Tutorial”

    HTML PHP is HTML

    One thing to realise here is that an HTML page can function as both an HTML page and as a PHP page. Let me explain:

    In the previous tutorial, we saw how a PHP file could be created by using the start and end tags, <?php and ?>. We also saw how these tags could start and stop as often as you wished. Within the context of a standard PHP file, this doesn’t make much sense. After all, what’s the point of stopping and starting the PHP code if we’re just going to be executing more of the same PHP?

    The answer lies in the fact that, between those PHP tags, we can output HTML content. Take the following code snippet as an example. This is the full text from a PHP file

    A sample PHP file<br/>
    <?php
     echo "And here is the second line";
    ?>

    Run this, and we see the output

    A sample PHP file
    And here is the second line

    Now, what’s going on here? You might well have guessed by now, the “echo” command is used to output data to the screen. But there’s no echo command on the first line, so how is this text appearing? And more importantly, you might ask, where’s the semicolon? I did say in an earlier tutorial that any PHP code without a semicolon at the end of each statement will fail. But the important thing to note here is that on line 1, before the <?php tag, that’s not PHP code

    Huh? What?

    PHP files can contain both static text and PHP code, the important thing to realise is that, whenever the code is between the <?php and ?> tags, it will be executed as PHP code

    The next page will go into a little more detail

    <<>>

Leave a Comment

Want to ask a question about anything in this tutorial? Have you spotted an inaccuracy, or noticed areas for improvement? Fancy just having a chat? Leave your comments below...

Recommended Reading from Amazon.com

Previous Tutorial
PHP Syntax


Next tutorial
Variables in PHP