- Difference between double quotation marks and single quotation marks:
Variables contained in double quotation marks are automatically replaced with actual values, while variables contained in single quotation marks are output according to common strings.
When using single quotes, you only need to escape the single quotes "'". When using double quotes ("), you also need to pay attention to the use of double quotes ("), ($) and other characters. These special characters must be displayed using the Escape Character.
Note: when defining a simple string, using single quotes is a more reasonable processing method. If double quotation marks are used, PHP will spend some time processing String Conversion and variable parsing. Therefore, to define a string, use single quotation marks unless otherwise required.
Unset () and is_null ()
Unset () clears the variable from the memory. Since PhP4, this function does not return values. When passed in as a reference, it only disconnects the binding between the variable name and the variable content, rather than destroying the variable content.
Is_null () is null, that is, if the variable is not assigned a value, Boolean is returned. If it is null, true is returned. Otherwise, false is returned.
Convert Data Types
You can directly convert the data type (type) var. The original variable does not change.
You can also use bool settype (mixed var, string type) for conversion. This method changes the original variable.
Predefined Variables
Variable name |
Description |
$ _ Server ['server _ ADDR '] |
IP address of the server where the script is currently running |
$ _ Server ['server _ name'] |
The name of the server host where the script is currently running. If the script runs on a VM, the name is determined by the value set by the VM. |
$ _ Server ['request _ method'] |
The Request Method for accessing the page. For example, get, Head, post, and put. If the request method is head, the PHP script stops sending the header information (this means that no output buffer is available after any output is generated) |
$ _ Server ['remote _ ADDR '] |
Browsing the IP address of the user on the current page |
$ _ Server ['remote _ host'] |
Browsing the user's host name on the current page, Reverse Domain name resolution based on the user's remote_addr |
$ _ Server ['remote _ port'] |
Port used by the user to connect to the server |
$ _ Server ['script _ filename'] |
The absolute path name of the currently executed script. Note: If the script is executed in CLI, it is used as a relative path, such as file. PHP or .. /file. PHP. $ _ server ['script _ filename'] will contain the relative path specified by the user |
$ _ Server ['server _ port'] |
The port used by the server. The default value is 80. If you use SSL to install the connection, the value is the http port set by the user. |
$ _ Server ['server _ signature '] |
A string containing the server version and Virtual Host Name |
$ _ Server ['document _ root'] |
The document root directory where the script is currently running. Defined in the server configuration file |
$ _ Cookie |
The information transmitted to the script through httpcookie. Most of these cookies are set through the setcookie () function when PHP scripts are executed. |
$ _ Session |
Contains information related to all session variables. $ _ Session variable is mainly used for session control and value transfer between pages |
$ _ Post |
Contains information about the parameters passed through the POST method. It is mainly used to obtain data submitted through the POST method. |
$ _ Get |
Contains information about the parameters passed through the get method. The main user obtains the data submitted through the get method. |
$ Globals |
Data composed of all the defined global variables. The variable name is the index of the array. It can be called a super set of all super variables. |
Operator
In PHP, + is only used for the + operation of numbers. The '.' symbol is used for string connection.
In PHP, '=' indicates constant. That is, not only the values are equal, but also the types of the two.
The @ symbol is an error blocking operator. $ err = @ (5/0) will not display the error message.