1. There are two ways to refer to a file: Require and include
The use of require is as follows require("MyRequireFile.php");
. This function is usually placed at the front of the PHP program, and before the PHP program executes, it is read into the file specified by require to make it a part of the PHP program's Web page. Commonly used functions, you can also use this method to introduce it into the Web page.
Include usage methods such as include("MyIncludeFile.php");
. This function is usually placed in the processing part of the process control. The PHP Program page reads the include file before it is read in. This way, you can simplify the process when the program executes.
2. Comments
PHP echo// This example is a comment for C + + syntax * * This example takes multiple lines of comment * / Echo "This is the first two examples. \ n" ; Echo # This example uses the UNIX Shell syntax annotation ?>
Note: The information explained is what and why.
3. Constant type
PHP defines some of the following constants in constants.
__file__
This default constant is the PHP program file name. If the reference file (include or require) is in the reference file, the constant is the reference filename, not the file name of the reference.
__line__
This default constant is the number of PHP program lines. If the reference file (include or require) is in the referenced file, the constant is the row that refers to the file, not the file line that references it.
Php_version
This built-in constant is a version of the PHP program, such as ' 3.0.8-dev '.
Php_os
This built-in constant refers to the name of the operating system executing the PHP parser, such as ' Linux '.
TRUE
This constant is the truth (true).
FALSE
This constant is a pseudo-value (false).
E_error
This constant refers to the most recent error.
E_warning
This constant refers to the most recent warning.
E_parse
This constant is a potential problem for parsing syntax.
E_notice
This constant is unusual but not necessarily the wrong place. For example, access a non-existent variable.
These e_ are the beginning of the constant, can refer to the error_reporting () function, there are more related instructions.
Of course, the above default constants are not sufficient when writing programs. The function of define () allows us to define the constants we need ourselves. See the following example
PHP define("COPYRIGHT", "copyright©2000, netleader.126.com"); echo COPYRIGHT; Echo __file__ ; ?>
4. Declaring variables (case-sensitive)
Php/** * @file variable.php * @author suguolong * @date 2015/07/29 16:49:08 * @brief * **//*Defining string Variables*/$mystring= "I am a string";$WilsonPeng= "Really serious author";$NewLine= "line up \ n";/*Defining integer Variables*/$int 1= 38;$int 2= 49;$hexint= 0x10;/*defining floating-point variables*/$float 1= 1.732;$float 2= 1.4E+2;/*Defining array Variables*/$MyArray 1=Array("Zi", "ugly", "Yin", "Mao"));$MyArray 2=Array( "Earthly Branches" =Array("Zi", "ugly", "Yin", "Mao"), "Zodiac" =Array("Rat", "ox", "Tiger", "Rabbit"), "number" =Array(1, 2, 3, 4) );/*definition of Class*/classFoo {functionDo_foo () {Echo"Doing foo.\n"; }}/*use of the class*/$bar=Newfoo;$bar-Do_foo ();$bar-Do_foo ();$bar-Do_foo ();/*Define a Boolean value*/$booleanval _true=true;$booleanval _false=false;/*Using Variables*/Echo"Boolean value of true: \ n";Echo$booleanval _true;Echo"\ n";Echo"Boolean value of false: \ n";Echo$booleanval _false;Echo"\ n";/*vim:set expandtab ts=4 sw=4 sts=4 tw=100:*/?>
5, the use of variables
When the program executes in PHP, the system preserves the area of a global variable in memory. In practice, the required variables can be removed by $GLOBALS ["Variable name"].
$GLOBALS arrays are special variables in PHP programs that do not have to be defined, and the system automatically matches the relevant variables inside. In the function, it is not necessary to $GLOBALS whether the array has been globally defined, it can be used directly.
Similar to $GLOBALS variables are $php _errormsg string variables. If the track_errors option in the PHP configuration file (Php.ini/php3.ini) is turned on, there will be a global variable $php _errormsg can see the wrong information.
In PHP, the effective range of global variables (scope) is limited to the main program, and does not affect variables with the same name in the function, that is, global variables and local variables do not violate each other. To make the variable transparent to the function, use the $GLOBALS array or use the global definition.
What do you do with the information that users enter in the FORM? If Track_vars is set to on in the PHP configuration file, it is good to use the variable name directly. As the following example, next.php in execution, the system will automatically generate two variables $username and $sex, the direct use of the good, compared to the traditional CGI to resolve their own, PHP is really amazing.
The above describes the PHP learning notes (1), including aspects of the content, I hope the PHP tutorial interested in a friend helpful.