How to Write Your Very First PHP Program
Superior programmers know a secret. The key that they know pertains to how a PHP program is constructed.
Right here is the key:
“Advanced applications are constructed up from easy applications. If you happen to can learn to create a easy program, you may learn to construct a fancy program, irrespective of how sophisticated.”
A program may be constructed of just a few traces. They all the time begin the identical approach. Begin with the PHP begin tag, adopted by your programming code, and final by the PHP finish tag.
The PHP program proven above has solely three traces. Line 1 & three are the beginning and finish tags, line 2 is your practical code. On this case nonetheless, line 2 is a remark and won’t carry out any particular motion aside from to remind you of one thing. Feedback are usually not processed by the interpreter. As soon as a remark is encountered, it’s mainly ignored.
The code in instance 1 behaves precisely because the code in instance 2. Regardless that instance 2 has 2 extra traces. If you happen to observed, the extra traces in instance 2 are solely feedback. As soon as once more they’re ignored by the PHP interpreter (PHP Engine).
If there may be one remark or a number of feedback, the interpreter will act the identical approach. It can ignore any feedback that it finds.
In instance three you will notice your first functioning PHP program. The ‘echo’ command was added to this program, situated on line three. An ‘echo’ assertion is a in-built PHP command that can output no matter follows it to the display screen. Anytime you need to output one thing utilizing PHP to the display screen, net browser, or visible show. Use the easy ‘echo’ command.
As you may see, the phrases ‘My First Actual Program’ follows the ‘echo’ command. It is extremely necessary to surround the phrases that you really want ‘echoed’ on the display screen inside single or double quotes. This fashion the echo command is aware of from what character to start out with, and
what character to finish with, because it generates the output to the display screen.
When the echo command is known as, it takes the contents contained in the quotes, and sends it out to the display screen – minus the quotes. So the output could be:
My First Actual Program
The output to this program could be:
You’re studying easy methods to program in PHP.
If you begin programming, there isn’t a restrict to what number of feedback and instructions you may enter in your program. Go forward, strive it your self. As you get higher you will not want so many feedback to remind you of what you might be doing in your program.
Advanced applications are made up of easy applications. Studying easy methods to combine easy instructions collectively, together with PHP begin and finish tags makes a completely functioning PHP program. As you might be studying, a great suggestion is so as to add as many feedback as you must assist keep in mind what you might be doing. Feedback are like taking notes you could refer again to. As you get higher at programming, you’ll naturally enter much less feedback. The PHP ‘echo’ command outputs characters to the display screen. Enclose all characters after an ‘echo’ command with single or double quotes.
Congratulations, you simply wrote your first PHP program.