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.

Instance 1:</p> <p>Line 1: <php Line 2: // your program goes here Line 3:?>

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.

Instance 2:</p> <p>Line 1: <php Line 2: // this is one comment Line 3: // this is another comment Line 4: // this is the last comment Line 5:?>

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.

Instance three:</p> <p>Line 1: <php Line 2: // below this line is a real PHP programming command Line 3: echo 'My First Real Program'; Line 4:?>

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

Instance four:</p> <p>Line 1: <php Line 2: // the next line is the first echo command Line 3: echo 'You are '; Line 4: // the next line is the second echo command Line 5: echo 'learning how to '; Line 6: // the next line is the last echo command Line 7: echo 'program in PHP.'; Line 8:?>

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.