What are the rules for PHP

PHP Basics Syntax

1. Basics

Think of the syntax of a programming language as follows. It is a set of rules that dictate how the code must be structured so that it can be processed correctly. Don't you understand Never mind, I tell you.

So, we have a youngster who is the code. This should now be understood by a gentleman of older age, i.e. the interpreter. If the former asks for the time, he shouldn't do it that way.

"Well, Alder, what's going on in the clock?"

In real life, the older man will probably suspect that someone wants to steal his watch and calls the police. When programming, however, a so-called parse error is thrown. This is a subtle indication that you have not followed the rules and that the information provided (the code) cannot be processed. Because the interpreter does not understand them.

2. The syntax rules of PHP

... are based on the so-called semicolon languages ​​such as C ++ or Java. There are a few very basic things that I am going to tell you right now. I'll go into the subtleties in a moment.

Comments

There are three different options here. First we have the one-line comment and it looks like this.

<?php  // Ein kurzer Kommentar?>

Alternatively, you can also use the following variant. Is especially something for the very typ-lazy, because you save a sign.

<?php  # Ein kurzer Kommentar?>

If, on the other hand, you want to write a short novel, you take advantage of this option.

<?php  /* Es war einmal vor langer Zeit, als ich diesen Code   geschrieben habe. Es war hinter den sieben Bergen  bei den sieben Programmierern ... */?>

The semicolon

Put simply, this defines the end of an instruction. Because it can get a little longer and since no one likes to scroll horizontally, it is then divided into several lines. And if the semicolon is missing at the end, the carton buzzes.

<?php  echo 'Wenn am Ende das Semikolon fehlt,         gibt es eine Fehlermeldung';?>

The curly braces

... is used for code blocks such as functions or conditions. The subtleties come later.

<?php  function irgendwas()  {    ...  }?>

3. Spellings

Unfortunately, PHP gives us a lot of freedom in a number of cases. Sometimes you can write something like that, or like that, or like that. First of all, an important note. Make it uniform! Then you (and others) can read the code properly. And when you're done with the basics, be sure to check out the programming styles section. There are important tips. So, now it really starts.

back to the previous section to the next section

Info

Last change in content

11.04.2014

Just learn to program!

Easy to understand programming books for all programming languages!

Implement your own loT projects!

Your expert for Arduino, Raspberry Pi and microelectronics!

job advertisements

More job offers