PHP knowledge points and summary, PHP knowledge points Summary
PHP: Hypertext Preprocessor
PHP is a server-side scripting language;
The PHP script is executed on the server;
Bytes --------------------------------------------------------------------------------------------------------------------------
PHP files can contain text, HTML tags, and scripts.
PHP file: the browser returns pure HTML
Bytes --------------------------------------------------------------------------------------------------------------------------
Every code in PHP must end with a semicolon. Splitting is a separator used to separate commands;
The basic commands for PHP output text are echo and print.
Bytes --------------------------------------------------------------------------------------------------------------------------
In PHP, the variable declaration method is to add "$" before the variable name. Note: When referencing the variable, remember to add "$ ";
To declare variables, you also need to know:
1. You do not need to declare the Data Type of the variable to PHP;
2. PHP automatically converts a variable to a correct data type based on the method configured for the variable;
3. In PHP, variables are automatically declared during use;
Naming rules for variables:
1. The variable name must start with a letter or underscore;
2. The variable name can only contain letters, numbers, and underscores;
3. The variable name cannot contain spaces. If the variable name is composed of multiple words, the variable name should be connected using underscores;
Bytes --------------------------------------------------------------------------------------------------------------------------
String variables are used to store and process text fragments;
Concatenation operator:
In PHP, there is only one string operator;
The concatenation operator (.) is used to connect two string values;
Bytes --------------------------------------------------------------------------------------------------------------------------
Echo strlen ($ str); // It indicates the length of the output string str;
Note: If the string contains "<br>", it must be 4 characters long !!!
Echo strpos ($ str1, $ str2); // search for str2 strings in str1;
Note: The subscript at the beginning of the string is 0, not 1;
Bytes --------------------------------------------------------------------------------------------------------------------------
The condition judgment statement in PHP is:
If .. else
Or: if... elseif... else ..
Multiple conditions use elseif or switch structure:
Note the following when using this structure:
1. Perform a calculation on the expression (usually a variable;
2. Compare the expression value with the case value in the structure;
3. If a match exists, execute the code associated with the case;
4. After the code is executed, use break to exit the structure. Otherwise, the subsequent code will be executed continuously;
5. If no case is true, use the default statement;
Bytes --------------------------------------------------------------------------------------------------------------------------
Array:
The method to define an array is:
$ Array name = array (array element );
How to get the number of array elements: count ($ array name) or sizeof ($ array name)
Method for outputting all elements in the array (code representation ):
Example:
<? Php $ name = array ("xiaoxiangxiang", "xiaohuihui", "lalala", "hahaha"); for ($ I = 0; $ I <sizeof ($ name ); $ I ++) {// or $ I <count ($ name); echo $ name [$ I]. "<br>" ;}?> // Remember to add $ before I;
Bytes --------------------------------------------------------------------------------------------------------------------------
Create a PHP function:
1. All functions start with the keyword function (). (The function declaration method is: function name ())
2. The function name should prompt for its function. The function name must start with a letter or underscore;
3. Add the braces of the "{" opening to the code of the function;
4. Insert the function code;
5. Add a "}" function to end by closing curly braces;
Bytes --------------------------------------------------------------------------------------------------------------------------
PHP form processing:
<form action="result.php" method="post">Name : <input type="text" name="name" />Age : <input type="text" name="age" /><input type="submit" /></form>
Note: Be sure to remember !!!
Form Verification:
User input should be verified whenever possible. Client verification is faster and server load can be reduced;
If the form accesses the database, it is very necessary to use server-side verification;
A good way to verify a form on the server is to pass the form to itself, rather than jump to different pages. In this way, you can get an error message on the same form page. Users are more likely to find errors.
Bytes --------------------------------------------------------------------------------------------------------------------------
Important:
$ _ GET variable is used to collect the values in the form from method = "get;
The $ _ GET variable is an array with the variable name and value sent by the http get method.
The $ _ GET variable collects the values in the form from method = "get. The information sent from a form with the GET method is visible to anyone. (Displayed in the address bar of the browser), and there is a limit on the amount of information sent (a maximum of 100 characters ).
<form action="result.php" method="get">Name : <input type="text" name="name" />Age : <input type="text" name="age" /><input type="submit" /></form>
In the result. php script file:
Your information as follows:<br><?phpecho "Name: ".$_GET["name"]."<br>";echo "Age : ".$_GET["age"]."<br>";?>
Note: When the $ _ GET variable is used, all variable names and values are displayed in the URL. Therefore, this method should not be used for sending passwords or other sensitive information. However, because the variables can be displayed in the URL, you can add the page to favorites.
The http get method is not suitable for large variable values. The value cannot exceed 100 characters;
Bytes --------------------------------------------------------------------------------------------------------------------------
Important:
The $ _ POST variable is an array with the variable name and value sent by the http post method.
The $ _ POST variable is used to collect the values in the form from method = "POST. The information sent from a form with the POST method is invisible to anyone (not displayed in the address bar of the browser) and there is no limit on the amount of information sent.
<form action="result.php" method="post">Enter your name: <input type="text" name="name" />Enter your age: <input type="text" name="age" /><input type="submit" /></form>
In the result. php script file, you can set the value of the variable $ _ POST:
Welcome <?php echo $_POST["name"]; ?>.<br />You are <?php echo $_POST["age"]; ?> years old!
Why use $ _ POST ??
1. variables sent through http post are not displayed in the URL.
2. There is no length limit on the variable.
Bytes --------------------------------------------------------------------------------------------------------------------------
Important:
The $ _ REQUEST variable in PHP contains $ _ GET, $ _ POST, and $ _ COOKIE content.
The $ _ REQUEST variable in PHP can be used to obtain the results of form data sent through the GET and POST methods.
Your information as follows:<br><?phpecho "Name: ".$_GET["name"]."<br>";echo "Age : ".$_GET["age"]."<br>";?>