PHP study notes, php notes

Source: Internet
Author: User
Tags bitwise operators domain name server microsoft iis

PHP study notes, php notes

PHP
(Personal homepage) is an embedded HTML language, a scripting language that is executed on the server side to embed HTML documents. Maintained by zend.
Why do I need to install a web server? Because our Browser needs to retrieve data from the web server Lake. The httpwatch tool can obtain the sent and received data, which helps us better understand. Besides the Appche server, the Microsoft iis server and the lighttpd server (read ligty.

Appche Server

The Appche server spans all platforms. You can remotely control the server through ssh software. In this case, use the command line. You can use the command line to manage appche. Cd: Switch the directory. After the appache is started, it occupies a port. The default port is port 80. One machine can have Port 1-. In development, you can use netstat-an to check which ports are being listened on. The fewer ports, the safer the system is. If abnormal port listening is found, you can disable this port. Use netstat-anb to find the program listening and disable it. A port can only be monitored by one program. A port is also allocated randomly when a request is sent from your computer. The port is included in the URL and is released when the request is used up.

Appche directory structure
Bin directory is used to store Common commands
Cgi-bin this directory stores Common commands in Linux
The conf directory is used to store configuration files.
Error directory stores error records during startup and Shutdown
The htdocs directory is used to store site files (html). Multiple sites can be classified by folders.
Icons directory storage icon
Appche logs recorded in the logs directory
Manual directory manual
The appche module of the modules directory is managed as a module

Procedure

1. Enable httpd-vhosts.conf files in httpd-conf

2. Configure in the httpd-vhosts.conf File

3. Modify the hosts file (review the real process of accessing a web page)
Detailed webpage access process
What happened after the browser press ENTER
1. Resolve the Host Name
2. query the local file hosts (in windows). There is an IP address in the file, and the relationship between the query and the domain name cannot be found. Go to the Internet dns domain name server to query the relationship between the IP address and the domain name, an http request is sent to appche. After receiving the request, appche needs to resolve the host, resolve the web site name, resolve the Resource Name, and retrieve a resource file. If yes, the page is returned.

One IP address (multiple ports) and multiple domain names bound
Solution 1: Use ports to differentiate sites

1. Activate your website first

2. Configure the virual hosts file in the httpd. conf file to enable the configuration of the virtual host.

3. Configure the httpd-hosts.conf file.

4. Add the ing between IP address and domain name in the hosts file

Add a new domain name and bind it to the IP address
1. Develop a new website

2. Add a new VM

3. In httpd. conf, enable appche to listen to port 81. appche can listen to multiple ports at the same time.

4. Add a new domain name to the hosts file.

Solution 2: differentiate different domain names through servername

1. Develop a new website

2. Add a configuration file to the httpd-vhosts.conf file, which is different from solution 1 configuration, to specify the domain name ServerName www.sth.com.

3. Add the ing between the IP address and the domain name in the hosts file, which is the same as solution 1.

The website resource file (including the PHP file) and appche are on the same machine, called the application server, and the browser is on another machine. Databases are generally not on application servers, but on dedicated database servers.

Appche and PHP need to be integrated. The PHP call process is as follows:
Press enter in the browser to resolve the host name such as sohu. If the IP address corresponding to the host name is not found, go to the Internet dns to query the host name. After obtaining the IP address, send an http request to appche, appche DNS host (appche manages multiple domain names), retrieves the SITE/directory, parses the Resource Name (which page of the website is specific), and returns the request file, the PHP code has been executed in appche. the browser obtains the code after the server executes the code, which is then parsed and displayed.
If the PHP code is modified, appche does not need to be restarted.

PHP basic syntax
<? Php?> And HTML can be nested with each other.
Note:/**/multiline, // single line, # Unix style.

PHP basic syntax, variables, constants, Data Types
1. Define a variable in php to start with the $ symbol. The data type of the variable is not fixed and determined based on the runtime context. Therefore, PHP is a programming language with weak data types.

2. PHP is case sensitive.
A valid variable starts with a letter or underscore.
Basic data types: integer, floating point, Boolean, and string
Composite data type: array, Object
Special Data Type: null Resource Type
In PHP, an integer generally occupies four bytes, one byte occupies 8 bits, the highest bit indicates the symbol bit, 0 indicates the positive number, and 1 indicates the negative number PHP_INT_SIZE
What is the maximum integer? You can use PHP_INT_MAX to check whether a negative integer is the same as the maximum value (absolute value) of a positive integer. If the Integer Range exceeds the maximum range, the automatic type is changed to the float type.

Floating Point Number: The maximum precision is 14 bits. It is calculated from the left and the first non-zero number starts to calculate the precision.

Character Type: A character occupies one byte. Theoretically there is no size limit, as long as it does not exceed the memory.
Comparison operator = equal to, = equal
Logical Xor or Xor: either of the two is true, but not both are true, true

Ternary Operators
Expression 1? Expression 2: expression 3

String Operators
.: Connect two strings (basic data type)

Type Operators
Instanceof is used to determine whether a variable belongs to a certain type (only object types can be determined)

Three process control statements
1. Sequential Control
2. Loop Control
3. condition Control
Switch (expression ){
Case constant 1: statement;
Break;
Case constant 2: statement;
Break;
Case constant 3: statement;
Break;
Case constant n: statement;
Break;
Defual: Statement; // No
Break;
}
Break statement: end the current loop or switch statement. You can give a number to indicate the number of the layer to exit. Break 3;
Break indicates that the game is not played, and continue indicates that the game is played again from the first level.
The continue can also contain a number indicating the number starting from the layer.
Constant: The $ symbol is not required before. Use the define () function instead of the assign value statement. The constant value is a scalar [basic data type] (string, integer, float, boolean). Once defined, the value cannot be modified ., You do not want to use constants when a value changes, such as the circumference rate and tax rate.
Constant names are all capitalized and separated by underscores
Two methods to define constants:
Define ("TAX_RATE", 0.08 );
Const TAX_RATE2 = 0.1;

Function: Call: require 'funcs. php ';
Function Name (parameter list ){
// Function body;
// Return statement. A result is returned.

}

Mutual page calls in PHP
To use functions defined in function01.php in a. php, we need to use the following functions:
The require () and require_once () functions.
Include () and include_once () functions.
<? Php
Require ('file name to be introduced ');

$ FilePath = "a. php"; // import with variables
Require $ filePath;

Require 'file name to be introduced ';
?>

When you execute a function, the code in the function is executed from a new stack, then returned to the function call, and then continues to execute the following code.

Advantages of require_once:
If the file is included, the former determines whether the file is included. If the file is included, the latter determines whether the file is not included. One can save resources, and the other can avoid repeated definition errors.

Include and include_once
You can include one page to another.

Difference between require and include
If an include error occurs, the request will continue and the request will terminate the execution.
We recommend that you use require_once, which is usually placed at the top of the php page.

How to understand the function call Process
According to the function execution rules, as long as the function is immediately opened up a new stack, the variables in each stack are independent of each other (space is independent of each other ).

Function parameters and variable scopes:

1. The function parameter list can have multiple parameters
2. The data type of the parameter list can be multiple, and any type supported by PHP
3. The name of a function is the same as that of a custom variable, but is case insensitive.
4. variables defined in a custom function are local and do not take effect outside the function.
5. When using global variables, you can use variables outside the function.
$ A = 12;
Function abc3 (){

Global $ a; // the outer layer $ a to be used in abc3 ()
$ A + = 45;

}
Abc3 ();
Echo $;
6. To prevent global variable confusion, you can use unset ($ var) to delete a variable.
Example: $ a = 12;
Function abc ($ ){

Unset ($ a); // indicates that $ a is no longer in the abc function range and $ a is not used. It is redefined later.
$ A = 45;
}
Abc ($ );
Echo $;

7. Default function values
You can assign a default value to some parameters.
Function abc ($ B, $ a = 2 ){

$ Res = $ a + $ B;
Return $ res;
}
$ E = 70;
Echo abc ($ e). '|'; // 72, $ a defaults to 2
Acho abc ($ e, 90); // 160
$ F = 80;
Echo abc ($ e, $ f );
8. PHP uses value transfer by default. If address transfer is required,
Function abc (& $ B) {// Add an address

$ B = 314;
}
Abc ($ a); // the address of $ a points to the address of $ B
Echo $ a; // 314-bit operation

Binary: returns two to one values. The binary values include 0 and 1, which is easy to implement electronically. At the same time, a combination of 0 and 1 can represent any number.
1. The highest bit of binary is the sign bit. 0 indicates a positive number, and 1 indicates a negative number.
2. The original codes, backcodes, and supplementary codes of positive numbers are the same.
Represents a number in binary format. This Code is the source code.
1 ......> source code 00000000 00000000 00000000
Negative Inverse code: the original symbol bit remains unchanged, and the others are reversed.
-1 ......> source code 10000000 00000000 00000000
-1 ......> Anti-code 11111111 11111111 11111111 11111110
Negative complement: Its anticode is added with 1
-1 ......> supplemental code 11111111 11111111 11111111 11111111
The anti-code and supplemental code of 0 are both 0.
PHP does not have an unsigned number. As long as it is a number, the highest bit is a symbol.
During computation on the computer, all computation is based on complement.
Whether positive or negative, it must be converted into a complement code and then calculated.

Bitwise operators
$ A & $ B And (bitwise And) will set the bits in both $ a And $ B to 1.
$ A | $ B Or (bitwise Or) will set the bit where $ a Or $ B is 1 to 1.
$ A ^ $ B Xor (bitwise Xor) sets the bitwise of $ a and $ B to 1.
~ $ A Nor (bitwise inversion) sets the bitwise 0 in $ a to 1, and vice versa.
$ A <$ B shift left: the bits in $ a are moved to the left for $ B (each movement represents multiplied by 2 ).
$ A> $ B shift right moves the bits in $ a to the right $ B (each movement indicates dividing by 2 ).
The first four are bitwise operations, and the last two are shift operations.
~ 2 =?
1. Obtain the 2's complement code 00000000 00000000 00000010
2. Retrieve the 11111111 11111111 11111101 (Supplemental Code)-"original code
11111111 11111111 11111100 // The complement code is reduced to the reverse code
10000000 00000000 00000011 //-3
So ,~ 2 =-3
Displacement Calculation rules
Right Shift of arithmetic: low Overflow, the symbol bit remains unchanged, and uses the symbol bit to fill the overflow high
Arithmetic shift left: The symbol bit remains unchanged, and the low position is 0.
$ A = 1> 2;
1. Find the complement Code of 1: 00000000 00000000 000000000 00000001
00000000 00000000 000000000 00000000
$ A = 0;
$ B =-1> 2;
1. Locate the-1 supplemental code: 10000000 00000000 00000000 00000001
11111111 11111111 11111111 11111110
11111111 11111111 11111111 11111111
2. Arithmetic shifts two places to the right 11111111 11111111 11111111 11111111
Result completion code-source code,
1111111 11111111 11111111 11111110 (subtract a variant of the reverse code)
10000000 00000000 000000000 00000001 (original code) //-1
-1> 2 =-1;

$ C = 1 <2;
1 complement: 00000000 00000000 00000000 00000001
Move two places left 00000000 00000000 00000000 00000100 // 4

Array, sorting, and searching
To know the total number of elements in the array, you can use the system function count: count (array name );

Array Creation
An array is a set of keywords and values.

. Create array 1
1. $ arr [0] = 123;
$ Arr [1] = 90;
$ Arr [2] = 8;
Array in memory: Each array element allocates a space. $ arr is equivalent to a floor, and each element represents a room.
In the PHP array, the Data Type of each element value is not limited.
. Create array 2
$ Array name = array (value 1, value 2, value 3 ...);

Subscript is also called a keyword. It can be a number or a specific one. (by default, the subscript of our element is numbered from 0)
$ Arr ['logo '] = "beijing ";
# Arr ['php'] = 123;
Or
$ Arr = array <"logo" => "Beijing", "php" => 123>

If a subscript is not specified for an element when an array is created, PHP will automatically use the largest subscript value, and Add 1 as the subscript (keyword) of the element)
We can usually use print_r to display this array.
Var_dump ($ arr) displays array information in more detail.
One-dimensional array use traps
$ Arr [bar] = 'Hello world'; this method is dangerous.
PHP array Functions
Count function: counts the number of count (array name) elements in an array ).
Is_array Function
Print_r () and var_dump () functions.
Explode function: Split string $ arr = explode ("", $ str); // split string $ str with space.

 

 

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.