PHP For Beginners - Lesson 2


1. You can place sections of PHP code anywhere in a document, but generally will do so in either the body or head (or you can make an entire document PHP, which then uses commands to output HTML).
2. To include a file of PHP instructions into a document, you can use an include, require, include_once, or require_once statement (for example: include 'header.php';).
3. To prevent an external PHP file from being included multiple times, you can use the include_once or require_once statement (for example, include_ once 'header.php';). Any additional attempts to load the file will be ignored.
4. To ensure that a PHP file gets included in a document, you can use the require statement (for example: require 'header.php';). If the file cannot be loaded, an error will be thrown.
5. To ensure that a PHP file is included and that it doesn’t get included more than once, you can use the require_once statement (for example: require_once 'heading.php';). If the file cannot be loaded, an error will be thrown, and any additional attempts to load the file will be ignored.
6. To create a single-line comment in PHP, start it with the // comment marker (for example, // This is a comment). All text after the comment marker to the end of the line is ignored.
7. To create a multiline comment in PHP, you start it with /* and end it with */ (for example, /* The contents between and including these two comment markers is completely ignored by PHP */).
8. To indicate that a PHP instruction is complete, you must place a semicolon character (;) after it (for example, echo "Hello world";). Failure to do this is one of the most common causes of errors for beginners.
9. The code $items = 120; $selection = 7; is legal PHP because multiple statements are allowed on a line, due to requiring semicolons after each instruction.
10. The code $items = 120 $selection = 7; will cause PHP to throw a parse error because there is no semicolon after the number 120 to separate the statements.

PHP For Beginners - Lesson 2

No comments:

Post a Comment