Hello, my audience, Hello! hello, everyone! welcome to the IT program Lecture Hall of the story about underpants. today I will share with you a little bit of knowledge.
Is the interaction between the frontend and the backend.
There are two terminologies in PHP, which indicate the difference between the current APP client and the webpage.
BS does not need to be downloaded for browsing
Views for downloading CS
Environment Construction
You need to download an XAMPP software on the network for installation. you are using the XAMPP for mac version.
Let's talk about what we need to use PHP.
MYSQL Apache (middleware) PHP, and why do I recommend that you install XAMPP? it is because he has already packed all the three of us. you only need to install the next step. if a single installation is required, it is very complicated for us. therefore, we recommend that you directly install XAMPP.
Well, you can search for the installation method of XAMPP. this is relatively simple. just go to the next step.
PHP label declaration method
Echo "hello word";?>
Hello word
In PHP, the table declares It indicates the end. echo indicates the meaning of print/output.
In addition, all our declaration files end with ***. PHP.
PHP comments
// Single line comment
# This is also a single line comment
/*
Multi-line comment, which spans many rows
*/
?>
Variable
The variable starts with $, followed by the variable name.
It may consist of letters, numbers, and underscores. it cannot begin with a number.
Case sensitive.
Chestnuts:
$ Name = "neiku ";
$ Age = 26;
$ Num = 15 + "12"; // $ num = 27;
In PHP, the plus sign is the sum, regardless of whether the subsequent number is of the string type. but if it is 15 + "ab12", then his value is 15, and he will skip ab12. but if there are 15 + "12ab", his value is still 27.
Variable assignment
There are two types of value assignment: direct value assignment and reference value assignment.
Chestnuts:
$ Sum = "hello ";
$ Sum2 = & $ sum; // after $ sum is added here, $ sum will assign his memory address to $ sum2. if $ sum2 is re-assigned, the value of $ sum also changes. this is a bit like a pointer in c.
Variable
Chestnuts:
$ Sum = "hello ";
$ Sum = "word ";
Echo $ sum; // output hello;
Echo $ {$ sum}; // output word;
Echo $ hello; // output word;
Here, you can add $ to the variable to assign a new value. it generates a new value. this is indeed a little strange. as for its usefulness ........ it is widely used. this can be used in our forin during traversal.
Super global variable
PHP provides many useful predefined variables to provide a large amount of environment-related information.
Print/output global variable: print_r ($ _ SERVER); here I will explain that print_r prints an array. for array-specific printing. all of our predefined variables belong to the array type. so he needs print_r to print it.
Print_r ($ _ SERVER );
He will print all your information.
All information
Here I will list some of our common methods separately.
Print_r ($ _ SERVER ['server _ name']);
It will return the host name of the server where your current script is running.
Host name of the current server script.
If you change 127.0.0.1 to localhost, its host name will also be changed to localhost or the IP address you put on your current computer before, it will become an IP address.
Print_r ($ _ SERVER ['remote _ ADDR ']);
Client IP address.
IP address
However, note that all he obtains here is the current IP address, but he cannot recognize localhost.
Print_r ($ _ SERVER ['request _ URI ']):
Obtain the current file path.
Current file path
Print_r ($ _ SERVER ['http _ USER_AGENT ']);
Obtains information about the current operating system and browser.
My system, my browser, and my middleware
$ _ Get
This variable contains information about the parameters passed using the get method.
Then write the PHP code in the index. PHP file.
$ Name = $ _ GET ['name'];
$ Pwd = $ _ GET ['pwd'];
Echo $ name;
Echo"
";
Echo $ pwd;
?>
Enter information on the page
321 321
321 321
After submission, the page is displayed.
321 321
However, please note that the get method will display your input information on the Web site.
Show your input information
So next I will introduce post to you.
Post
This variable contains information about the parameters passed using the post method.
If the html code is above, I will not write it. depressed. I will not let you copy this post. The only difference is that method = "post" will change his request method to post.
PHP code is the same as above.
Enter information on the page
321 321
321 321
After submission, the page is displayed.
321 321
This time, the page will not have your input information.
$ _ REQUEST
This variable records the variables that are passed to the script through various input methods, such as get and post, but do not use this super variable because it is insecure and slow.
$ _ COOKIE
Cookie variable array
$ _ SESSION variable array
Session variable array
$ _ FILE
Array of variables related to files uploaded
$ _ ENV
Environment variable array
$ _ GLOBALS
All global variable arrays
Constant
A constant is a value that cannot be modified during program execution, such as PI (3.14159236 );
Constants are case sensitive. generally, constant names are uppercase.
Constants are global and can be used anywhere in the script.
Constants are dividedBuilt-in constantsAndCustom constants;
Constants are defined using the define () function.
Chestnuts:
Define ('pi ', 3.1415926 );
Echo PI; // 3.1415926
Built-in constants
The constant of the operating system where PHP_ OS PHP is located.
PHP_VERSION: The current PHP version.
Magic constant
The current row number in the _ LINE _ file.
_ FILE _ complete FILE path and FILE name;
_ FUNCTION name.
_ CLASS name.
_ METHOD _ class METHOD name.
Data type string
There are three defining methods for a string: single quotes, double quotation marks, and delimiters;
Variables in single quotes are not replaced by variable values.
The most important aspect of a double quotation mark string is that the variable is replaced by the variable value.
If you encounter the dollar sign $, the parser will retrieve as many characters as possible to form a valid variable name. if you want to explicitly specify the end of the name, enclose the variable name in brackets.
Chestnuts:
$ Sum = "hello ";
Echo = "welcome to china, I am ***, {sum} s ";
The delimiter syntax is used for string demarcation. <
Chestnuts:
$ Str = <AAA
Dasfdas fdsafdasfdsa
Fdsafdsaf fdsasadf
AAA;
Echo $ str; // dasfdas fdsafdasfdsa fdsafdsaf fdsasadf
Str
Str
Note:
The row where the end identifier is located cannot contain any other characters, which means that the identifier cannot be indented. before the semicolon, there cannot be any spaces or tabs.
String conversion
\ N line feed \ r press enter \ t Tab (Tab creation );
\\\ (Backslash) \$ $ (dollar sign) \ "" (double quotation marks)
Integer
$ Age = 25;
Floating point type
$ Age = 5.29;
Boolean
$ Bu = TRUE;
$ Bu = FALSE;
Composite data type
Array
$ Week = array ('Monday', 'Tuesday', 'weday ');
Object
$ Db = new db;
Special Data types
Resources
$ Fh = fopen ("text.txt", "r"); open a file or path. if the file fails, false is returned.
Null
Null: null indicates no value. null indicates no space or 0. null is considered null in the following cases;
No predefined variables are set.
The specified value is null;
Use the unset () function to clear.
Automatic type conversion
Because PHP is very loose in the definition of the type, sometimes it will automatically convert the variable to the most suitable type according to the environment that references the variable.
Chestnuts:
$ Num = 5;
$ Str = "15 ";
Echo $ num + $ str; // 20;
$ Str = "100 hello ";
$ Num = 200;
Echo $ str + $ num; // 300.
$ Str = '1. 2 ';
If ($ str) {// judge whether $ str is true or false
Echo "hello word ";
} // Hello word;
Type-related functions
The type of the variable returned by gettype (). There are 8 types in total.
String
Integer
Float
Boolean
Array
Object
Null
Unkonw unknown
Chestnuts:
$ Sty = "hello ";
Echo gettype ($ sty); // string
Is_type ();
Check whether the variable belongs to a certain type. If yes, 1 is returned. If no, no is returned.
Chestnuts:
$ Arr = array (1 );
Echo is_array ($ arr); // 1;
$ Num = 5;
Echo is_int ($ num); // 1;
Var_dump ();
Obtains detailed information about the value and type of a variable.
Chestnuts
$ Str = 'hello ';
Echo var_dump ($ str); // string (5) "hello"
$ Arr = array ('A', 'B', 'C ');
Echo dump ($ arr); // array (3) {[0] => string (1) "A" [1] => string (1) "B" [2] => string (1) "C "}
Well, some PHP knowledge will be briefly introduced here and will be updated in the future. thank you for reading this article. if you have any suggestions, thank you for your comments.