- When PHP parses a file, it looks for opening PHP tag "<?php or <?" and ending php tag " ?>" which tell PHP to start and stop interpreting the code between them.
- Everything outside of a pair of opening and closing tags is ignored by the PHP parser. Example:
1
2
3
4
5
| <p>This is going to be ignored by PHP Parser.</p>
<?php echo 'While this is going to be parsed.'; ?>
<p>This will also be ignored by PHP parser.</p>
|
- PHP code must have a semicolon ";" at the end of each statement.
- The closing PHP tag "?>" automatically insert a semicolon.
- Example:
1 2 3 4 5 6 7
<?php echo 'PHP is Fun to learn !!'; ?> <br> <?php echo 'PHP automatically insert a semicolon at the last closing tag' ?> <br> <?php echo 'If a PHP file have only PHP code than the last closing tag can be omitted';
- Example Advanced escaping
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| <?php
if ($expression) {
?>
<strong>This is true.</strong>
<?php
} else {
?>
<strong>This is false.</strong>
<?php
}
?>
|
- Before PHP version 7 There were four different pairs of opening and closing tags which could be used in PHP. Standard tag is always available Example: Script tag is also always available Example:
1
2
3
| <script language="php">echo 'some editors (like FrontPage) don\'t like processing instructions';
</script>
|
- Short tags can be turned on and off from the php.ini configuration file. Example:
1
| <?= expression ?>
|
- This is a shortcut for
1
| <? echo expression ?>
|
- ASP style tags can be turned on and off from the php.ini configuration file Example:
1
| <% echo 'You may optionally use ASP-style tags'; %><%= $variable; # This is a shortcut for "<% echo . . ." %>
|
PHP for the Web: Visual QuickStart Guide (5th Edition)
No comments:
Post a Comment