The 1.PHP code can consist of the following four parts:
- Html
- PHP tags
- PHP statements
- Space
PHP tags usually start with "<?php", with "? > "End.
Four styles of 2.PHP markers
- XML style: <?php echo ' <p> Order processed.</p> ';? This is a recommended style for PHP, and server Administrators cannot disable this style of tagging, so this style of tagging is guaranteed to be available on all servers, which is especially important for applications that write different server environments.
- Short style: < Echo ' <p> Order processed.</p> ';? This style of marking is the simplest and follows the style of SGML (standard Universal Markup Language) processing instructions. To use this markup style, you must enable the Short_open_tag option in the configuration file, or enable the short mark option to compile PHP. This style is not recommended because it is not supported in the default settings for many environments.
- Script style: <script language = ' php> echo ' <p> Order processed.</p> '; </script>, this style is the longest, but people who are familiar with Iavascript or VBScript may be more accustomed to it.
- ASP style:: <% echo ' <p> Order processed.</p> '; %>, this style is the same as the ASP tag style. If Asp_tags is enabled in the configuration settings, it can be used, but the markup style is disabled by default.
3. Precautions
- In PHP statements, semicolons are used to separate statements. Missing semicolons is a common syntax error.
- In the PHP language, the spacer such as the carriage return, and the spaces and tabs are considered spaces. PHP will ignore them by default. So they are not applied to separate statements. To write code to a line, you can use the join operator "." To write in a single line of code. When sending output to the browser using the Echo command, you can use this connector to avoid writing multiple echo commands.
- the difference between single and double quotes: A single quote indicates that it is a string that will send the contents of the quotation mark to the browser, and the double quotes will parse the contents of the quotation marks, as the variable will replace it with its value.
4. Notes
Multiline comment: Start with "/*", End with "*/"
Single-line Comment: C + + style, beginning with "//", Shell scripting style, beginning with "#". A single-line comment is a comment from the beginning of the label to the end of the line.
5. Accessing the form
In PHP, you can access each form field in the form of a PHP variable, where the name of the PHP variable must match the name of the form field. The variable name for PHP starts with the $ symbol.
There are three ways to access form data through variables, depending on the PHP version and settings:
There are three ways to access the contents of the Tireqty domain:
- $tireqty; The short style is convenient, but you need to set the Register_globals configuration option to on, which is off by default for security reasons.
- $_post[' Tireqty ']; Medium Style recommended! Creating short versions of variable names based on medium style doesn't create a security problem.
- $HTTP _post_vars[' Tireqty ']; The lengthy style has been deprecated.
Medium style involves retrieving variables from one of the $_post, $_get, $_request arrays, and if the data is submitted through the POST method, the data entered in the Tireqty text box is saved in $_post[' Tireqty ', if submitted by the GET method, The data will be saved in $_get[' Tireqty '). In either case, the data can be obtained by $_request[' Tireqty '.
These arrays are called Super Global (Superglobal) variables.
6. methods for specifying strings
- Single quotation marks
- Double quotes
- Heredoc syntax
Interpolation: The operation of replacing a variable with a string is an interpolation (interpolation). This string can be quoted in double quotation marks.
Variables and text: a single quotation mark indicates that inside is a string that will send the contents of the quotation marks to the browser (in textual form), and the double quotation marks will parse the contents of the quotation marks, as the variable will replace it with its value.
Heredoc Syntax: Specifies the character tag of an end string to specify a long string. Such as:
Echo<<<theend
Line1
Line2
Line3
TheEND
The Heredoc string is interpolated, just like a double-quoted string.
PHP and MySQL Web Development Study notes Chapter 1-1.5 Getting Started