PHP Learning Notes

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

Php
(Personal homepage) is an HTML-embedded language that is a scripting language for embedded HTML documents executed on the server side. Maintained by Zend Company.
Why do I need to install a Web server? Because our browser wants to fetch data from the Web server lake. The HttpWatch tool can get the data sent and received, which will help us understand more thoroughly. Server In addition to Appche also have Microsoft IIS server, LIGHTTPD server (read ligty) and so on.

Appche Server

Appche servers across all platforms. The server can be remotely controlled via SSH software. This is the command line to use. Management Appche can use the command line. CD: Switch directories. After the Appache is started, it consumes a port and the default 80 port listens. A machine can have port 1-65535, in development, you can use Netstat-an to see which ports are listening. The fewer ports the more secure. If an abnormal port listener is found, you can close the port. Use NETSTAT-ANB to find out which program is listening and thus shuts down. A port can only be monitored by one program. The computer sends the request also has the port, is randomly allocated, contains in the URL, runs out to release.

Appche directory Structure
The bin directory is used to store frequently used commands
Cgi-bin This directory holds common commands under Linux
Conf directory to store configuration files
Error logging when the error directory holds startup and shutdown
Htdocs directory for storing site files (HTML) Multiple sites can be categorized by folder.
Icons Directory store icon
Logs directory records Appche related logs
Manual Catalogue Brochure
Modules Catalog Appche module Appche managed in a modular format

Configuration steps for a virtual host

1. Enable the httpd-vhosts.conf file in httpd-conf

2. Configure in the httpd-vhosts.conf file

3. Modify the Hosts file (revisit the real process of accessing a Web page)
detailed description of the process of accessing the Web page
What happens when the browser returns
1. Resolving host Names
2. Query the local file hosts (Windows), the file has an IP address, query and domain name relationship, query, go to the external DNS domain name server to query the relationship between IP and domain name, found that will send an HTTP request to Appche, Appche get the request to resolve the host, Resolves the Web site name resolution resource name, takes out a resource file, and returns the page if it is fetched.

One IP (multiple ports) and multiple domain bindings
Scenario One: Differentiate different sites by port

1. Develop your own website first

2. Configure our httpd.conf file to enable the Virual hosts file inside, that is, to start the configuration of the virtual host

3. Configure the httpd-hosts.conf file.

4 Add IP and domain name correspondence in the Hosts file

Add a new domain name to the IP binding
1. Develop a new website

2. Add a new virtual host

3 Let Appche monitor 81 port in httpd.conf, Appche can listen to multiple ports simultaneously

4 Adding a new domain name to the Hosts file

Scenario Two: Distinguish different domain names through the servername end

1. Developing a new website

2. Add the configuration file in the httpd-vhosts.conf file, and the configuration of the scheme is different, to specify the domain name servername www.sth.com.

3. Add IP and domain name correspondence in the Hosts file, same as scenario one.

Website resource files (including PHP files) and Appche on the same machine, called Application server, browser on another machine. The database is not typically on an application server, but on a dedicated database server.

Appche and PHP need to be integrated, the PHP call process is as follows
Browser Enter, resolve the host name such as Sohu, query and host name corresponding IP, not found on the external DNS query, found, get IP appche send HTTP request, Appche resolution host (Appche manage multiple domain names), remove the site/directory, Parse out the name of the resource (the specific page of the site), the request file back, PHP code in the Appche has been executed, the browser gets the server after the execution of the code, and then the resolution is displayed.
The PHP code modifies the need not to restart Appche.

PHP Basic Syntax
<?php?> and HTML can be nested with each other.
Note:/**/multiple lines,//single line, #Unix风格.

PHP basic syntax, variables, constants, data types
1 define a variable in PHP to begin with the $ symbol, the data type of the variable is not fixed and is determined by the runtime context. So PHP is a weak data type programming language.

2.PHP is case-sensitive.
A valid variable is preceded by a letter or underscore
Basic data types: Integer, Float, Boolean, string
Composite data types: arrays, objects
Special data type: null resource type
In PHP, an integer typically accounts for four bytes, one byte is 8bit, the highest bit represents the sign bit, 0 is a positive number, and 1 is a negative number php_int_size
What is the maximum of an integer? With Php_int_max, negative integers and positive integer maximums (absolute values) are the same. If the integer range exceeds the maximum range, the automatic type becomes a float type.

Floating-point number: Precision maximum 14 bits, calculated from the left, the first non-0 to begin the calculation of precision

Character type: One character occupies one byte, theoretically no size limit, as long as not more than memory can be
Comparator = = equals, = = = Congruent
Logical XOR or XOR: Two has a true, but not both true, true

Ternary operators
Expression 1? Expression 2: Expression 3

String operators
.: Connect two strings (base data type)

Type operator
Instanceof is used to determine whether a variable is of a certain type (only the object type can be judged)

Three major Process Control statements
1. Sequential control
2. Cycle 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;//Can not
Break
}
Break statement: Ends the current loop or switch statement and can give a numeric representation of the exit to the first level. Break 3;
Break represents not playing games, continue said to start playing again from the first.
Continue can also take a number that indicates the beginning of the first level.
Constants: The $ symbol is not required in front. Defined by the Define () function, but not by an assignment statement; the value of a constant is a scalar [basic data type] (String,integer,float,boolean), and once defined, its value cannot be modified. , do not want a value to change when using constants, such as pi, tax rate.
The name of the constant is all uppercase, with the underscore interval
Two ways to define constants:
Define ("Tax_rate", 0.08);
Const tax_rate2=0.1;

Function: Call: Require ' funcs.php ';
Function name (argument list) {
function body;
Return statement, which returns a result that can be no.

}

Pages in PHP call each other
In order to complete the functions defined in function01.php in a.php, we need to use the following function:
Require () and require_once () functions.
Include () and include_once () functions.
<?php
Require (' filename to be introduced ');

$filePath = "a.php";//By variable Introduction
Require $filePath;

Require ' filename to be introduced ';
?>

Executing a function executes the code from a new stack, then returns to the function call and proceeds to the following code.

Advantages of require_once:
The former encounters the containing file, which determines whether the file is already included and is no longer included if it is included. One can save resources, and two can avoid duplicate definitions of errors.

Include and include_once
Can include one page to another page, using the same

Require and include differences
Include encountered error will continue execution, require will terminate execution
It is recommended to use require_once, usually placed in front of the PHP page

How to understand the invocation procedure of a function
According to the rules of function execution, as soon as a function is seen to open a new stack, the variables between the stacks are independent (space is independent of each other).

function parameters and variable scopes:

1. The parameter list of a function can have more than one parameter
2. The parameter list data type can be multiple types, PHP supports any type
3. Functions are named as custom variables, but are not case-sensitive
4. A variable defined in a custom function is local and does not take effect outside the function
5. Use a variable outside of the function when you are working with global variables
$a = 12;
function ABC3 () {

Global $a;//To use the outer $ A in ABC3 ()
$a +=45;

}
ABC3 ();
echo $a;
6. To prevent global variables from confusing, you can use Unset ($var) to delete a variable
Example: $a = 12;
Function ABC ($a) {

unset ($a);//represents no longer within the range of the ABC function, does not use $ A and is later redefined.
$a = 45;
}
ABC ($a);
echo $a;

7. Default value issues for functions
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 default is 2
Acho ABC ($E, 90);//160
$f = 80;
Echo ABC ($e, $f);
8.PHP is the default value delivery, if you need address delivery,
Function ABC (& $b) {//Add address character

$b = 314;
}
ABC ($a);//$a address pointing to the address of $b
echo $a;//314-bit operation

Binary: Every binary one, using binary only 0 and 12 numbers, easy to implement electronically, at the same time, through the combination of 0 and 1 can represent any one number.
1. The highest bit of the binary is the sign bit, 0 is a positive number, and 1 indicates a negative number
2. Positive source code, anti-code and complement are the same
Use binary to represent a number, this code is the source code
1.......> Original Code 00000000 00000000 00000000 00000001
Negative number of the inverse code: the original code symbol bit unchanged, the other is to take the reverse
-1......> Original code 10000000 00000000 00000000 00000001
-1......> Anti-code 11111111 11111111 11111111 11111110
The complement of negative number: It's anti-code plus 1
-1......> complement 11111111 11111111 11111111 11111111
0 of the anti-code, the complement is 0
PHP has no unsigned number, as long as the number, the highest bit is the symbol
In a computer operation, it is calculated in the form of a complement.
Whether it's positive or negative, it's going to be converted to a complement and then calculated.

Bitwise operators
$a & $b and (bitwise AND) will set the bit to 1 in $ A and $b to 1.
$a | $b or (bitwise OR) sets the bit to 1 in $ A or $b to 1.
$a ^ $b Xor (Bitwise XOR) will set the different bits in $ A and $b to 1.
~ $a Nor (bitwise reverse) sets the bit in $ A to 1 and vice versa.
$a << $b shift left shifts the bits in $ A to $b times (each move represents a multiply by 2).
$a >> $b shift right shifts the bits in $ A $b times (each move is represented by 2).
The first four are called bitwise operations, and the following two are shift operations
~2=?
1. Find out 2 of the complement 00000000 00000000 00000010
2. Take counter 11111111 11111111 11111101 (complement)-"Original Code"
11111111 11111111 11111100//complement minus one get anti-code
10000000 00000000 00000011//-3
So, ~2=-3
Rules for displacement operations
Arithmetic right shift: low overflow, sign bit invariant, and sign bit fill overflow high
Arithmetic left shift: sign bit unchanged, low 0
$a =1>>2;
1. Find the 1 complement: 00000000 00000000 000000000 00000001
00000000 00000000 000000000 00000000
$a = 0;
$b =-1>>2;
1. Find the complement of-1:10000000 00000000 00000000 00000001
11111111 11111111 11111111 11111110
11111111 11111111 11111111 11111111
2. Arithmetic right shift two bit 11111111 11111111 11111111 11111111
Result complement-the original code,
1111111 11111111 11111111 11111110 (minus one-change anti-code)
10000000 00000000 000000000 00000001 (original code)//-1
-1>>2=-1;

$c =1<<2;
1 Complement: 00000000 00000000 00000000 00000001
Shift left two-bit 00000000 00000000 00000000 00000100//4

Array, sort, find
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 collection of keywords and values

. Create an array one
1. $arr [0]=123;
$arr [1]=90;
$arr [2]=8;
How arrays exist in memory: Each array element is assigned a space, $arr equivalent to a floor, and each element represents a room
In the PHP array, the data type of each element value is not limited
. Creating an array two
$ array Name =array (value 1, value 2, value 3 ...);

The subscript is also called the keyword, can be a number, you can also specify (by default, our elements of the subscript is starting from 0 to you number)
$arr [' logo ']= ' Beijing ';
#arr [' php ']=123;
Or
$arr =array< "Logo" = "Beijing", "PHP" =>123>

If we create an array without assigning a subscript to an element, PHP automatically uses the current largest subscript value, plus 1 as the subscript for that element (the keyword)
We can usually use Print_r to show this array condition
Var_dump ($arr) to display the information of an array in more detail
One-dimensional arrays use traps
$arr [bar]= ' Hello World '; it's dangerous to use.
PHP array-related functions
Count function: The number of count (array name) of the statistic array element.
Is_array function
Print_r () and Var_dump () functions.
Explode function: Splits the string $arr=explode ("", $str),//splits the string $str with a space.

PHP Learning Notes

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.