Before we can do the big fancy stuff we must first learn the basics from which we build on.
- Start by creating a blank file using any program that can save in plain text format.
- Save your file as a .PHP file, for example mypage.php. Saving a page with the .php extension tells your server that it will need to execute the PHP code.
- Enter the statement <?php to let the server know that there is PHP code coming up.
- After this we would enter the body of our PHP program.
- Enter the statement ?> to let the browser know the PHP code is done.
Every section of PHP code starts and ends by turning on and off PHP tags to let the server know that it needs to execute the PHP in between them. Here is an example:
Everything between the <?php and ?> is read as PHP code. The <?php statement can also be phrased as simply <? if desired. Anything outside of these PHP tags is read as HTML, so you can easily switch between PHP and HTML as needed. This will come in handy later in our lessons.