Basic php learning Notes

Source: Internet
Author: User
Tags html header php basics
This article mainly introduces the basic knowledge of php learning notes. For more information about php learning notes, see this article.

I have been studying php for more than a year, and I have accumulated a lot of notes. I 'd like to write an article.

Php Basics

Syntax:

foreach (array_expression as $value){ statement};foreach (array_expression as $key => $value){ statement};

Parametersarray_expressionIs the array to be traversed,$valueIs the value of the array

 "; }?>

The above code will be output:
Name: Marry
Name: Lorry
Name: mike

Two important magic methods

1. _ set () method: This method is used to set values for private member attributes. There are two parameters. The first parameter is the attribute name for the set value, the second parameter is the value to be set for the attribute, with no return value. 2. _ get (): This method is used to obtain the attribute value of a private member. there is a parameter that is used to input the name of the member attribute you want to obtain and return the obtained attribute value, this method does not need to be manually called.

Methods in php are case insensitive.

Require (dirname (_ FILE __). '/global. php '); // introduce the global FILE require (dirname (_ FILE __). '/config. ini. php '); // introduce the basic configuration file

Object operator and double colon operator

In the Member methods of the class, you can use the-> (object operator ):$this->property(Property is the property name) to access non-static properties.
Static attributes are used::(Double colon ):self::$property.

=> And->

=>Array member access symbol,->Object member access symbol;
$this->$name=$value:nameSet the variable value$value;
$thisRepresents the class itself,->Is the operator used to access its class members.
Double colon operator (::) Class name::Static attributes/methods
"::"Is used to call static attributes and methods in the class.

include(): Contains external files. the syntax format is include (string filename );
require(): Will output the error message, terminate the script
include_once(): When the same file is called multiple times, the program will only call once
require_once(): First, check whether the file has been called elsewhere.
array_pop(): Get and return the last element in the array
count(): Count the number of elements in the array
array_search(): Get the key name of the element in the array
$array_keys(): Get all key names of repeated elements in the array

Single quotation marks and double quotation marks

PHP treats the data in single quotes as a normal string and does not process it any more. Double quotation marks also process the strings.

Get and post

$ _ GET [] and $ _ POST [] Global Arrays: they are used to receive the data transmitted to the current page by the GET and POST methods, respectively. "[]" Contains name.

There are three common methods for passing php parameters: $ _ POST [], $ _ GET [], and $ _ SESSION [], which are used to obtain the values of form, URL, and Session variables respectively.

The differences between get and post methods in form submission are summarized as follows:

GET gets data from the server, and POST transfers data to the server. GET adds the parameter data queue to the URL referred to by the ACTION attribute of the submission form. the values correspond to each field in the form one by one and can be seen in the URL. POST uses the http post mechanism to place fields in the form and their content in the html header and send them to the URL address referred to by the ACTION attribute. You cannot see this process. For the GET method, the server uses Request. QueryString to obtain the value of the variable. for the POST method, the server uses Request. Form to obtain the submitted data. The size of data transmitted by GET is small and cannot exceed 2 KB (this is mainly because the URL length is limited ). The amount of data transmitted by POST is large, which is generally not restricted by default. However, theoretically, the limit depends on the server's processing capability. GET is less secure and POST is more secure. Because GET data is stored in the request URL during transmission, many existing servers, proxy servers, or user proxies record the request URL to the log file, and put it somewhere, so that some private information may be seen by a third party. In addition, you can also directly view the submitted data in the browser, and some internal messages of the system will be displayed in front of the user. All POST operations are invisible to users.

If Method is not specified during FORM submission, the default value is GET request (. net is POST by default). The data submitted in Form will be appended to the url? Separated from the url. The letter and number characters are sent as they are, but spaces are converted to "+". Other symbols are converted to % XX, XX represents the ASCII (or ISO Latin-1) value in hexadecimal notation. The data to be submitted for the GET request is placed in the HTTP request header, while the data to be submitted by POST is placed in the object data. the data to be submitted by the GET method can contain up to 2048 bytes, POST does not have this restriction. The parameters passed by POST are in the doc, that is, the text transmitted by the http protocol. when accepted, the parameter section is parsed. Obtain parameters. Generally, it is better to use POST. The data submitted by POST is implicit. GET is passed in the url to pass some data that does not need to be kept confidential. GET is passed through parameters in the URL, and POST is not.

1. the GET request data will be appended to the URL (that is, the data is placed in the HTTP header? Splits the URL and transmits data. parameters are connected with each other

2. the data submitted in GET mode can only be 1024 bytes at most. Theoretically, there is no limit on POST. a large amount of data can be transferred. The maximum size of IIS4 is 80 kB, and that of IIS5 is KB.

HTTP status code

Other information can be stored in the COOKIE if it needs to be retained.

Php code specification

1. variable assignments must be equal to spacing and arrangement

2. no extra spaces are allowed at the end of each line.

3. ensure that the file name is the same as the call case, because the file name is case sensitive on Unix-like systems.

4. the method name can only consist of letters. the underline is not allowed. The first letter must be in lower case, and the last letter of each word must be in upper case.

5. the attribute name can only consist of letters, and the underline is not allowed.

6. for access to object members, we must always use the "get" and "set" methods.

7. when the class member method is declared as private, it must begin with a double underline; when declared as protected, it must begin with a single underline; the member attribute declared as public cannot contain underscores at any time.

8. if we need to define some frequently used methods as global functions, we should define them in the class in static form.

9. the name of the function should be in lower case and underline, so that you can clearly describe the function of the function.

10. both Boolean and null values are in lower case.

11. when a string is composed of plain text (that is, it does not contain variables), it must always use single quotes (') as the delimiter.

12. when the array type is used to declare the joined array, it should be divided into multiple rows to ensure the alignment of keys and values in each row

13. all code in the class must be indented with four spaces

14. variables cannot be declared using var. class member variables must be declared using private, protected, and public. The get and set methods are usually used to sort class members.

15. the method must always use private, protected, or public to declare its scope.

16. unnecessary spaces are not allowed between the function or method name and parameter brackets.

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.