PHP Basics continued

PHP Basics

  • PHP runs on different platforms.
  • PHP is compatible with almost all servers used today.
  • PHP is FREE to download from the official PHP resource.

How to save PHP files?

PHP files have the extention .php. PHP files are not different from HTML files. It is basically a simple HTML or any other SGML file having some php script in between. No matter where it is placed, PHP code is executed before any of the HTML code. The only difference is that the file must have the extention .php, else the parser will not parse it.

PHP syntax

A PHP block can occur anywhere in any SGML file. The syntax for the same is given below:

<?php PHP script here ?>

Some servers have shorthand support and the syntax for PHP in such cases is:

<? PHP script here ?>

But it’s always recommended to avoid the shorthand way and use the former way.
Have a look at a simple PHP script given below:

<html> <body><?php echo "My first PHP program"; ?></body> </html>

The above example will send the text “My first PHP program” to the browser. One thing to note is that every statement in the PHP code must have a semi-colon in the end. “echo” is a statement that outputs the text to the browser.

If you have found my website useful, please consider buying me a coffee below 😉