First, the concept of PHP
Hypertext Preprocessor Hypertext preprocessor is an open source scripting language. Its syntax absorbs the characteristics of C language, Java, and Perl. It is used in the field of web development.
PHP is to embed the program into the Html document to execute, which is more efficient.
2. Operating environment
Make sure to run php:
Test: echo "abc";
Make sure the time zone is set correctly:
测试:echo date(“Y-m-d H:i:s”);
Make sure the module settings are correct:
Test: new mysqli("localhost", 'root', '123');
3. The grammatical environment
Grammar one:
<?php
..... here is the php code
?>
Grammar two:
<script language=”php”>
....here is the php code
</script>
Special: (the effect of carriage returns before and after <>)
<?php
echo '234'
If there is nothing below, do not write the end, no effect
If the writing ends, the following carriage return will be output as a space.
<?php before writing a carriage return will output a space before 234
Case:
Variable names, constants are case sensitive
Function name, system keywords are indistinguishable
4. Variables
Meaning: An "identifier" that contains a name and a value.
$a = 1;
Note: As long as the $ symbol appears, followed by the next character, it will be recognized as a variable
The variable must be assigned a value, and if it is assigned twice, it is to modify the variable.
When using it, remember to use the $ sign for $a
isset() determines whether a variable exists
Exist is not true, does not exist and is not false, if it is null, the output is also false
unset() remove
Break references between variable names and data instead of deleting data.
The value-passing method between variables: the default is value-passing, and if it is passed by reference, you need to pass the symbol &
Pass-by-value: refers to copying a copy of the data content of a variable and assigning it to another variable. The two variables are independent of each other.
For example: $v1=1;
$v2 = $v1;
$v1++;
echo "$v1,$v2"
then output 2, 1
Pass-by-reference: refers to copying the reference relationship of a variable and assigning it to another variable. When one data is changed, the other data will also be changed.
For example: $v1=1;
$v2 = &$v1;
$v1++;
echo "$v1,$v2"
then output 2,2
But when unset() deletes a variable, it doesn't affect another data.
Variable variables: (only in php)
Refers to the name of a variable, which is another variable.
$v1 = "abc"; //this is a string variable whose content is the string "abc"
$abc = 10; //This is a normal variable whose content is the number 10
echo $$v1; //At this time, it is the so-called "variable variable"
Predefined variables: super global variables, all arrays
PHP predefined variables are for all scripts, PHP provides a large number of predefined variables for scripts. These variables represent all external variables as built-in environment variables, and error messages as return headers.
Its scope is superglobal, which means they are available in all scopes of a script.
Scope:
Global scope: defined outside a function
Local scope: defined within a function, used only within a function
$GLOBALS $_SERVER $_REQUEST $_POST $_GET $_FILES $_ENV $_COOKIE $_SESSION
$_GET (array)
In html
Form one :
<form action=”abc.php” method=”get” >
项目1: <input type=”text” name=”uName” />
项目2: <input type=”password” name=”uPswd” />
<input type=”submit” value=”提交” />
</form>
Form two :
<a href=”abc.php?uName=test1&uPswd=123” > 文字。。。</a>
Form three :
<script>
location.href = "abc.php?uName=test1&uPswd=123"; //Using the attribute href of the location object
</script>
Form four :
<script>
location.assign( "abc.php?uName=test1&uPswd=123"); //Using the method assign() of the location object
</script>
php
<?php
$v1 = $_GET['uName']; //Single quotes can also be double quotes, which are essentially a string, but are actually the key name (subscript) of the array
$v2 = $_GET['uPswd']; //The key name must be exactly the same as the name when submitting (case sensitive)
?>
The above are put into different variables respectively, and then output.
Or you can use the method that outputs the entire array
<?php
var_dump($_GET);
?>
$_POST (array)
The same as GET, usually, the form form in the web page generally uses the post method, and the get method is mainly reflected in the other three forms.
$_REQUEST (array)
All data can be submitted for get and post
If the data of get and post have the same name, POST will overwrite the GET data.
request_order = "GP"; //This is the default value, G for GET, P for POST
Change to: request_order = "PG", the order is reversed