As a beginning student of PHP, you must understand 3 important fundamentals. Your lesson will begin with three definitions.
– scripting language
– start/end tags
– interpreter
A scripting language is the way a programming language was created to read and process your programming code. A scripting language like PHP uses start and end tags to start and end this process. These tags tell the built in interpreter that PHP programming code is between these tags. Line 1 and line 3 below are the PHP Start/End tags.
Example 1
[Line 1]
The PHP Interpreter is the built in part of the programming language that reads and processes the code that you write. The code that you write is your program. In the example above, the Interpreter reads line 2. Line 2 is a comment, a way to place information inside your PHP program so you can remember it.
PHP is an interpreted language, which simply means the processing of your program is done on the fly. As your programming code is read by the interpreter, it is processed in that very moment — line by line.
[note]
Java, on the other hand, is a compiled programming language. It has a built in compiler. Java is the opposite of PHP, and the ‘in the moment processing’. The built in compiler processes (reads) your code and creates a compiled copy before it can be used.
PHP is a scripting language. The code you write is processed in the moment. This processing begins when the built in interpreter finds a PHP start tag. It then reads and processes your programming code. This continues, line by line, until the interpreter finds the matching PHP end tag.
The interpreter is the ‘processing engine’ of PHP. It runs behind the scenes reading in your PHP programming code, processing the instructions that you wrote, and then performing the actions you commanded it to do. This process is automatic. To start and stop the Interpreter (processing engine), you must use scripting tags.
There are two main PHP Scripting Tags. One is the the PHP start tag, the other is the PHP end tag. Start and End tags tell PHP to start ‘processing’ your page
For example, using PHP to output your favorite color to the screen, you would type:
Example 2
[Line 1]
Line 1 and line 3 are the start and end tags. These tags tell the interpreter to start interpreting (reading and processing) the PHP commands contained within them. In this case the Interpreter reads the line 2:
echo ‘My favorite color is blue’;The built in command ‘echo’ tells the processing engine to output to the screen whatever follows it. In the example above. The output to the screen would be:
My favorite color is blueEasy PHP Programming Steps:
Step 1. Start the processing by writing the start tag as shown on line 1.
Step 2. Place your PHP commands next. Do not forget to end all your commands with a semicolon.
Step 3. End the processing with the end tag as shown on line 3.
Step 4. Save your program file with a ‘.php’ extension (i.e. getTheDate.php)
Conclusion
PHP is a scripting language. It has a built in interpreter. A scripting language uses start and end tags to call the interpreter. An interpreter reads and processes your programming code. Your PHP program can be one line or thousands of lines. But it starts and ends the same way every time — with a PHP start tag and PHP end tag.