From 39e467d1b7cbda39653bd9621097fa9524a39f55 Mon Sep 17 00:00:00 2001 From: Derek Ford Date: Thu, 20 Jan 2005 08:42:54 +0000 Subject: [PATCH] restructured the docbook elements to follow Rewrote the sections, which were redundant, and added a few more examples. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@177726 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/basic-syntax.xml | 294 +++++++++++++++----------------------- 1 file changed, 119 insertions(+), 175 deletions(-) diff --git a/language/basic-syntax.xml b/language/basic-syntax.xml index 68a1d31286..83a5efb805 100644 --- a/language/basic-syntax.xml +++ b/language/basic-syntax.xml @@ -1,156 +1,31 @@ - + Basic syntax - - - Escaping from HTML - - When PHP parses a file, it simply passes the text of the file - through until it encounters one of the special tags which tell it - to start interpreting the text as PHP code. The parser then - executes all the code it finds, up until it runs into a PHP - closing tag, which tells the parser to just start passing the text - through again. This is the mechanism which allows you to embed PHP - code inside HTML: everything outside the PHP tags is left utterly - alone, while everything inside is parsed as code. - - - - There are four sets of tags which can be used to denote blocks of - PHP code. Of these, only two (<?php. . .?> and <script - language="php">. . .</script>) are always available; the - others can be turned on or off from the - &php.ini; configuration file. While the - short-form tags and ASP-style tags may be convenient, they are not - as portable as the longer versions. Also, if you intend to embed - PHP code in XML or XHTML, you will need to use the - <?php. . .?> form to conform to the XML. - - - - The tags supported by PHP are: - - - - - Ways of escaping from HTML - + When PHP parses a file, it looks for opening and closing tags, + which tell PHP to start and stop interpreting the code between + them. Parsing in this manner allows php to be embedded in all + sorts of different documents, as everything outside of a pair + of opening and closing tags is ignored by the PHP parser. + Most of the time you will see php embedded in HTML documents, + as in this example. + + - -2. - This is a shortcut for "" - -3. - -4. <% echo ("You may optionally use ASP-style tags"); %> - <%= $variable; # This is a shortcut for "<% echo . . ." %> +

This is going to be ignored.

+ +

This will also be ignored.

]]> -
-
-
- - - The first way, <?php. . .?>, is the preferred method, as it - allows the use of PHP in XML-conformant code such as XHTML. + + - - The second way is not available always. Short tags are available - only when they have been enabled. This can be done via the - short_tags function (PHP 3 only), by enabling - the short_open_tag - configuration setting in the PHP config file, or by compiling PHP - with the option to - configure. Even if it is enabled by default in - php.ini-dist, use of short tags are discouraged. - - - - The third way is always available and safe like the first one. However, - the first is the preferred and most used one. - - - - The fourth way is only available if ASP - tags have been enabled using the asp_tags - configuration setting. - - Support for ASP tags was added in 3.0.4. - - - - - - - Using short tags should be avoided when developing applications - or libraries that are meant for redistribution, or deployment on - PHP servers which are not under your control, because short tags - may not be supported on the target server. For portable, - redistributable code, be sure not to use short tags. - - - - - - The closing tag for the block will include the immediately - trailing newline if one is present. Also, the closing tag - automatically implies a semicolon; you do not need to have a - semicolon terminating the last line of a PHP block. - Closing tag of a PHP block at the end of a file is optional. - - - - PHP allows you to use structures like this: - Advanced escaping + You can also use more advanced structures: + + Advanced escaping echo or - print or somesuch. + print. + + + There are four different pairs of opening and closing tags + which can be used in php. Two of those, <?php ?> and + <script language="php"> </script>, are always available. + The other two are short tags and ASP + style tags, and can be turned on and off from the &php.ini; + configuration file. As such, while some people find short tags + and ASP style tags convenient, they + are less portable, and generally not recommended. + + + Also note that if you are embedding PHP within XML or XHTML + you will need to use the <?php ?> tags to remain + compliant with standards. + + + + + + PHP Opening and Closing Tags + + + +2. + This is a shortcut for "" + +3. + +4. <% echo ("You may optionally use ASP-style tags"); %> + <%= $variable; # This is a shortcut for "<% echo . . ." %> +]]> + + + + + While the tags seen in examples one and two are both + always available, example one is the most commonly + used, and recommended, of the two. + + + Short tags (example three) are only available when they are + enabled via the short_open_tag + &php.ini; configuration file directive, or if php was configured + with the option. + + + If you are using PHP 3 you may also enable short tags via + the short_tags function. This + is only available in PHP 3! + + + + + ASP style tags (example four) are only available when + they are enabled via the asp_tags &php.ini; + configuration file directive. + + + Support for ASP tags was added in 3.0.4. + + + + + + + Using short tags should be avoided when developing applications + or libraries that are meant for redistribution, or deployment on + PHP servers which are not under your control, because short tags + may not be supported on the target server. For portable, + redistributable code, be sure not to use short tags. + +
- Instruction separation - - - Instructions are separated the same as in C or Perl - terminate - each statement with a semicolon. - - - The closing tag (?>) also implies the end of the statement, so - the following are equivalent: - + As in C or Perl, PHP requires instructions to be separated + with a semicolon at the end of each statement. The closing tag + of a block of PHP code automatically implies a semicolon; you + do not need to have a semicolon terminating the last line of a + PHP block. The closing tag for the block will include the immediately + trailing newline if one is present. - + + + The closing tag of a PHP block at the end of a file is optional, + and in some cases is helpful when using output buffering and + include or require. + + + - - Comments - + Comments - PHP supports 'C', 'C++' and Unix shell-style comments. For example: + PHP supports 'C', 'C++' and Unix shell-style (Perl style) comments. For example: @@ -223,11 +176,14 @@ if ($expression) { - - The "one-line" comment styles actually only comment to the end of - the line or the current block of PHP code, whichever comes - first. + The "one-line" comment styles only comment to the end of + the line or the current block of PHP code, whichever comes first. + This means that HTML code after // ?> WILL be printed: + ?> skips out of the PHP mode and returns to HTML mode, and + // cannot influence that. + If asp_tags configuration directive + is enabled, it behaves the same with // %>. @@ -239,13 +195,11 @@ if ($expression) { - 'C' style comments end by the first encountered */. You should be careful not to nest 'C' style comments, which can happen when commenting out large blocks. - @@ -259,16 +213,6 @@ if ($expression) { - - - The one-line comment styles actually only comment to the end - of the line or the current block of PHP code, whichever comes first. - This means that HTML code after // ?> WILL be printed: - ?> skips out of the PHP mode and returns to HTML mode, and - // cannot influence that. - If asp_tags configuration directive - is enabled, it behaves the same with // %>. -