PHP Knowledge points and summary

Source: Internet
Author: User
Tags php form php form processing alphanumeric characters
PHP: Hypertext Preprocessor
PHP is a server-side scripting language;
PHP scripts are executed on the server;
--------------------------------------------------------------------------------------------------------------- -----------
PHP files can contain text, HTML tags, and scripts
PHP file to return pure HTML to the browser
--------------------------------------------------------------------------------------------------------------- -----------
Each code in PHP must end with a semicolon. Good division is a delimiter used to separate instructions;
The basic instructions for the output text of PHP are echo and print.
--------------------------------------------------------------------------------------------------------------- -----------
In PHP, the method of declaring a variable is: "$" before the variable name, note: When referencing a variable, be sure to add "$";

Declaring variables also requires knowing:
1. You do not have to declare the data type of the variable to PHP;
2. Depending on how the variable is set, PHP automatically converts the variable to the correct data type;
3. In PHP, variables are automatically declared when they are used;

Naming rules for variables:
1. The variable name must begin with a letter or an underscore "_";
2. Variable names can only contain alphanumeric characters and underscores;
3. Variable names cannot contain spaces. If the variable name consists of multiple words, the underscore should be used to connect;
--------------------------------------------------------------------------------------------------------------- -----------
String variables are used to store and manipulate text fragments;

collocated operators:
In PHP, there is only one string operator;
The collocated operator (.) is used to concatenate two string values;
--------------------------------------------------------------------------------------------------------------- -----------
echo strlen ($STR); Indicates the length of the output string str;
Note: If the string contains "
"Here's a 4-word Fu Yi!!!"

Echo Strpos ($str 1, $str 2); Find in string str1 whether it contains a string str2;
Note: The subscript for the first position of the string is 0, not 1;
--------------------------------------------------------------------------------------------------------------- -----------
The conditional judgment statement in PHP is:
If.. Else
Or: If. ElseIf. else..

Multiple conditions with ElseIf or switch structure:

The problems to be noted with this structure are:
1. The expression (usually the variable) is calculated once;
2. Compare the value of an expression with the value of a case in the structure;
3. If there is a match, the code associated with the case is executed;
4. After the code executes, be sure to exit the structure with a break, otherwise you will always execute the following code;
5. If no case is true, use the default statement;
--------------------------------------------------------------------------------------------------------------- -----------
Array:
The methods for defining an array are:
$ Array name = Array (array element);

How to get the number of array elements: Count ($ array name) or sizeof ($ array name)

Method (code representation) of all elements in the output array:
Cases:
 
  ";}? >//Note I must remember to add $ before;

--------------------------------------------------------------------------------------------------------------- -----------
To create a PHP function:
1. All functions begin with the keyword function () (the function is declared by: function name ())
2. The name of the function should indicate his function, the function name begins with a letter or an underscore;
3. Add "{" The opening of the curly braces after the section is the code of the function;
4. Insert function Code;
5. Add a "}" function to close the curly braces;
--------------------------------------------------------------------------------------------------------------- -----------
PHP form Processing:
Note: Be sure to remember!!!

Form validation:
User input should be validated whenever possible. Client authentication is faster and can reduce server load;
If the form accesses the database, it is very necessary to use server-side authentication;
A good way to validate a form on a server is to only son the table to itself rather than jump to a different page. This allows the user to get an error message on the same form page. Users are also more likely to find errors.
--------------------------------------------------------------------------------------------------------------- -----------

Key points:
The $_get variable is used to collect values from a form method= "get";

The $_get variable is an array of variable names and values that are sent by the HTTP GET method.

The $_get variable collects the values from the form method= "get". The information sent from a form with a Get method is visible to anyone. (It appears in the browser's address bar), and there is a limit to the amount of information sent (up to 100 characters).

In the result.php script file:
Your information as follows:
"; echo" Age: "$_get[". "
";? >

Note: When using the $_get variable, all variable names and values are displayed in the URL, so this method should not be used when sending passwords or other sensitivities. However, because the variable can be displayed in the URL, you can bookmark the page in your Favorites folder.
The HTTP get method is not suitable for large variable values; The value cannot exceed 100 characters;
--------------------------------------------------------------------------------------------------------------- -----------

Key points:
The $_post variable is an array of variable names and values that are sent by the HTTP POST method.
The $_post variable is used to collect values from the form method= "POST". The information sent from a form with a post method is not visible to anyone (not displayed in the browser's address bar), and there is no limit to the amount of information sent.


In the result.php script file, the variable $_post is evaluated by:
Welcome 
 
   .
You are years old!

Why use $_post??
1. The variables sent over HTTP POST are not displayed in the URL.

2. Variable has no length limit.

--------------------------------------------------------------------------------------------------------------- -----------
Key points:
The $_request variable in PHP contains the contents of $_get, $_post, and $_cookie.

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:
"; echo" Age: "$_get[". "
";? >
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.