Php study notes (1): php study notes. Php learning Notes (1), php learning Notes 1. there are two ways to reference files: require and javasderequire, for example, require (MyRequireFile. php );. This function is usually put in php study notes (1), php study notes
1. there are two methods to reference files: require and include.
The use of require is as follows:require("MyRequireFile.php");. This function is usually placed at the beginning of the PHP program. before the PHP program is executed, it will first read the file specified by require to make it a part of the PHP program webpage. This method can also be used to introduce common functions into webpages.
The use of include is as follows:include("MyIncludeFile.php");. This function is generally placed in the process of process control. The PHP program webpage reads the include file. In this way, you can simplify the process during program execution.
2. Notes
Note: the information to be interpreted is what and why.
3. constant type
PHP defines the following constants in constants.
_ FILE __
The default constant is the PHP program file name. If a file is referenced (include or require), the constant in the referenced file is the referenced file name, rather than the file name.
_ LINE __
The default constant is the number of PHP programs. If a file is referenced (include or require), the constant in the referenced file is the row of the referenced file, rather than the row of the file.
PHP_VERSION
This built-in constant is the 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 that executes the PHP parser, such as 'Linux '.
TRUE
This constant is the true value (true ).
FALSE
This constant is a pseudo value (false ).
E_ERROR
This constant indicates the most recent error.
E_WARNING
This constant refers to the nearest warning.
E_PARSE
This regular expression is a potential problem with the parsing syntax.
E_NOTICE
This regular expression is unusual but not necessarily an error. For example, you can access a non-existent variable.
For more information about constants starting with E _, see error_reporting.
Of course, when writing a program, the above default constants are not enough. The define () function allows us to define the required constants. See the following example.
4. declare variables (case sensitive)
Array ("child", "ugly", "Yin", "Mao"), "Zodiac" => array ("rat", "ox", "Tiger ", "Rabbit"), "number" => array (1, 2, 3, 4);/* class definition */class foo {function do_foo () {echo "Doing foo. \ n ";}}/* class use */$ bar = new foo; $ bar-> do_foo (); $ bar-> do_foo ();/* defines the boolean value */$ booleanval_true = true; $ booleanval_false = false;/* use the variable */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 STSS = 4 tw = 100: */?>
[suguolong@cp01-rdqa-dev004.cp01.baidu.com sugl]$ php variable.php Doing foo.Doing foo.Doing foo.boolean value of true: 1boolean value of false: [suguolong@cp01-rdqa-dev004.cp01.baidu.com sugl]$
5. use of variables
During PHP program execution, the system retains a region of global variables in the memory. You can use $ GLOBALS ["variable name"] to retrieve required variables.
$ GLOBALS array is a special variable in the PHP program and does not need to be defined. The system will automatically match the relevant variable in it. In functions, you do not need to worry about whether the $ GLOBALS array has been globally defined.
Similar to the $ GLOBALS variable, there are $ php_errormsg string variables. If the track_errors option in the PHP configuration file (php. ini/php3.ini) is enabled, the global variable $ php_errormsg can be used to view the error message.
In PHP, the scope of global variables 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 infringe upon each other. $ GLOBALS array or global definition is required to allow variables to pass through the function.
What should I do with the information input by the user in FORM? If track_vars is set to On in the PHP configuration file, you can simply use the variable name. Next. during php execution, the system will automatically generate two variables $ username and $ sex, which can be used directly. compared with the traditional CGI, PHP is amazing.
Example (1), php Study Notes 1. there are two methods to reference files: require and include require, for example, require ("MyRequireFile. php ");. This function is usually placed in...