PHP basic notes

Source: Internet
Author: User
PHP basic notes:

To organize knowledge points to the blog Park, each Knowledge Point should be matched with the code test, and the code is independently typed. Organize the installation and configuration operations into documents and code.

Han Shunping recommended

Study Linux kernel

Research algorithm

Research on Network Technology (network management, network security)

Research Database

PHP notes. php is currently managed by zend. mysql (mysql-> sun-> oracle) (LAMP) is cross-platform and supports multiple databases. it is highly efficient and secure. Free to use; open source code (learning other people's code); Php4, php5 began to support object-oriented weak data type Web sites: WEB sites are a collection of multiple web resources. Simply put, you can think of a web application as a directory on the hard disk, which is used to manage multiple web resources. Websites are generally called Web websites or web projects/projects.

The basic concept of PHP is personla homepage. Currently, zend manages php embedded into html code. php scripts run on server 1994 (php1.0), 1995 (php2.0), and 1997 (php3.0 ), 2000 (php4.0), 2008 (php5.0) Php6.0 added: better support for web2.0, better support for Unicode, more support for object-oriented programming, and support for XMl programming, soap (simple object protocol)

L There is an important principle in software development: the compiling and running environments must be consistent.

L find the materials on the official website and use more English websites.

Compared with B/S and C/S, the development cost is low, the management and maintenance are simple, the product upgrade is convenient, the training cost for users is low, the user is easy to use, and the probability of failure is small; lack of security; clients cannot change with your mind and are limited by browsers. Learn about the content sent and received. Tool: httpwatch Lighttpd server. The nginx server Apache manual manages apache and uses the command line to manage httpd? K start [shutdown | restart] Httpd. conf Apache Directory structure Apache server

Bin: This directory is used to store common apache commands, such as httpd and apachemonitor.

Cgi-bin: This directory stores common commands in Linux. sh

Conf: stores the configuration file httpd. conf.

Error: error Record

Htdocs: folder for storing our sites (by default). if there are multiple sites, you can use folders to classify them.

Icons: storage icon

Logs: logs related to apache

Manual: manual

Modules: apahche module

When Apache is started, it loads related modules for reading httpd. conf.

Running mechanism diagram

Mpm: mutil processing module multi-processing module

Apr: Portable Runtime Library

Apache virtual directory for lifecycle configuration

We put the web application under the default apache hdocs directory, and apache will automatically manage it.

L add a virtual directory node

# Welcome page

DirectoryIndex index.html index.htm, index. php

# Site alias

Alias/myblog "D:/myblog"

# Access permission settings

Order allow, deny

Allow from all

L comment DocumentRoot "D:/phpenv/apache/htdocs"

10. access permission settings

# Set permissions for the myblog file under drive D

# Allow access from all ip addresses first, and deny access from all ip addresses. check allow and deny first.

Order allow, deny

# First Look At allow

Allow from all

Case

# Check deny first and then allow. setting in allow overwrites deny.

Order deny, allow

Allow from 218.0000253.2

# Ip addresses starting with 218.20 are rejected

Deny from 218.20

11. VM settings

L enable httpd-vhosts.conf: Add in the httpd. conf file

Include

L configure virtual hosts on \ extra \ httpd-vhosts.conf

# Configure the welcome homepage

DirectoryIndex index.html index.htm index. php

Options FollowSymLinks

# Do not allow others to modify our page

AllowOverride None

# Setting access permissions

Order allow, deny

Allow from all

L modify the hosts file to redirect www.sohu.com to a local page

Exercise:

In the Httpd. conf file, configure a virtual host (a website or site) of www.sohu.cn, and then register the host www.sohu.cn in the window system.

Enable the httpd-vhosts.conf in the httpd. conf file to remove,

Include conf/extra/httpd-vhosts.conf

Assume that our VM is running on c: \ myweb (a website)

Set http-vhosts.conf files

Add the ip ing between our ip address and host in the hosts file: c:/windows/system32/drivers/etc/hosts

(Think about configuring the public Ip address and intranet ip address for the hosts domain name)

The homepage is set as the homepage of the web application.

L webpage access process

Example: access http://www.sohu.com/news.html

1) resolution host www.sohu.com

2) query the local hosts File: windows/sys32/drivers/../hosts (the domain name corresponding to ip127.0.0.1)

3) If the ip address is not found in the local Hosts file, go to the dns (Domain Name Server) ip domain name

4) find the ip address

5) send an http request packet

6) Apache parses the http request package: parses the host, the site name, and the resource name.

7) obtain resources

12. configure Apache to support php (apache does not process php by default)

Software package: appserver or wmap. This software packages and installs the environment we need

Integration of Php and apache (that is, apache can handle php ):

# Load apache into the php processing module

LoadModule php5_module ~ Php installation path/php5apache2_2.dll

# Phpinidir: specifies the php INI file,

PHPIniDir "~ Php module installation path"

# This configuration indicates that php processes a resource *. php.

AddType application/x-httpd-php. php. phtml

Change the php. ini-devlopment file to php. ini. Because our php settings need to be modified in php. ini. Start the development mode.

Specify the extension module path extension_dir = ~ in php. ini ~ Php installation path/ext (which contains many functional libraries, shape libraries, database libraries, etc.), specifying the php Extension Library path

Allow php to support mysql: enable php_mysql in php. ini

If the function is not started, an error is reported.

Install mysql

Install phpmyadmin (phpmyadmin is a site, so extract it to the root directory of the website)

Install and configure the discuz Forum

1) prepare a discuz Forum code

2) decompress it to the root directory of the website.

3) copy the upload file of discuz to the discuz folder.

4) modify the config. inc. php. database configuration and an administrator $ forumfounders = 'admin

5) access http: // localhost/discuz'

Complete configuration: multiple sites exist on one server, allowing each site to configure a domain name

Solution 1:

1) identify different sites through ports: Prepare for binding a site

Modify httpd. conf to enable Virtual host configuration Virtual hosts; configure the httpd-vhosts.conf file; add the ing between ip and domain name in the hosts file;

Add a new domain name and bind it to the ip address.

Add virtual host 127.0.0.1: 81 in httpd-vhosts.conf

Let apache Listen to port 81: add a Listen 81

Add a new domain name 127.0.0.1 www. ***. com to the hosts file.

Access www. ****. com: 81 through a browser

Solution 2:

Differentiate domain names by using the ServerName Port

Add configuration in httpd-vhosts.conf files:

ServerName www. ****. com

DirectoryIndex news.html

PHP variables (note that the concepts of data and variables are different) php variables are defined with a $ header. The data types of php variables are changed, the data type of php variables is determined by the context during the runtime. Php is a programming language for weak data types (data types should not be transferred in and out) php basic data types: integer, decimal (float type) float/double (php does not distinguish between single precision and double precision ), boolean, string

Php compound type: array, object)

Php special data type: null, resource type (resource): $ conn = mysql_connect ("localhost", "root", "root ");

$ A = 890;

Var_dump ($ );

$ A = 1.1;

Var_dump ($ );

?>

Integer details

A) octal sequence: $ a = 0123;, hexadecimal format $ a = 0xAH;

B) Php does not support unsigned integers, that is, php integers are all signed numbers. It generally occupies 4 bytes. You can use PHP_INT_SIZE to display your machine. an integer is represented in several bytes. Echo PHP_INT_SIZE; maximum integer echo PHP_INT_MAX. if the value exceeds, the integer is automatically converted to float. (the maximum and minimum values must be sorted)

C) if a given number exceeds the integer range, it will be interpreted as float.

Practical questions:

$;

// If only $ a is written, but no value is assigned

Var_dump ($ a); // NULL, indicating no memory space is allocated

Echo $;

?>

Code considerations: robustness, scalability, security, code efficiency (concurrency, efficiency) Boolean type details

A) True and false are case insensitive.

B) the following values are treated as false:

Boolean value FALSE itself

Integer value 0

Floating point value 0.0

Empty string and string "0"

Array that does not contain any elements

Objects that do not include any member variables

Special type NULL (including unset variables)

Floating point details

A) floating point number (also known as double precision or real number), the floating point number precision is 14 (from the left start, the first non-zero number is the precision start; $ a = 0.23456789022222988; $ B = 0.00002222233334444;

B) the length of the floating point number is related to the platform. Generally, the maximum value is 1.8e308 with 14-digit decimal digits (this limit is important)

String details

A) one character occupies one byte; $ a = "hello"; occupies five bytes.

B) theoretically, we have no limit on the size of the string, that is, only the memory size cannot be exceeded.

C) when defining a string, we can use single or double quotation marks. The difference is as follows: double quotation marks will explain the value of the variable. If the string is enclosed in single quotes, \ is output in addition to processing \ ", and other rules are the same.

When a variable is included in the "" sign, its value is output, and the character itself is output in the 'sign.

Automatic conversion of Php character types

The type of the variable is not set by the programmer. Specifically, it is determined by the PHP runtime based on the context used by the variable. you can use var_dump ($ Variable 1, $ Variable 2 ...) To display its type. (PHP can be run without Compilation)

10. php constants

A) there is no dollar sign before the constant $

B) constants are defined by the define () function or the const, but not by the value assignment statement. The initial value must be assigned during the definition. the names of constants are generally uppercase and separated by underscores;

Define ("TAX_RATE", 0.08); if we do not want a value to change in the program, consider using constants, such as the circumference rate, tax rate ....

Const TAX_RATE = 0.08;

C) constants can be defined and accessed anywhere regardless of the scope of variables;

D) once defined, a constant cannot be redefined or canceled;

E) the constant value is a scalar [basic data type :]

11. expression

Expressions are the most important cornerstone of PHP. Almost everything written in PHP is an expression.

The so-called expression is anything with values. $ A = 7/3; how to save the number of decimal places to two places (function processing)

Comparison operator: $ a ===$ B all equal $! = $ B is not full (the value is equal and the type is the same)

$! = $ B is true only when the values are not equal

$! = $ B is true if the value is not equal or the type is not equal

String operator (.): When two basic data types are connected with., the content is concatenated as a string.

Type operator: instanceof is used to determine whether a PHP variable belongs to an instance of a certain class. You cannot determine whether the data belongs to the basic data type.

12. The data types that the Switch can use can be integer, decimal, string, Boolean, or null. From the perspective of if and switch branches, if is often an interpretation of a certain range, while switch is a judgment of a point.

Basic Concept of PHP functions: a set of program commands (statements) to complete a function. In php, functions are divided into user-defined functions and system functions (functions provided by the php statement itself can be directly used. The php designer believes that during project development, A lot of people will use some features ). Basic function structure:

Function name (parameter ...) {

// Function body

Return value; (optional)

}

Function parameters can be multiple, and the data type is any type supported by the php language; the name of the function is the same as the custom variables, the first letter can only be _, A-Z, a-z start, do not start with a number or special character.

Mutual page calls in Php

A) require () and require_once ()

It is usually placed at the beginning of the php page. before php is executed, it first reads the page contained in require. once an error occurs, it exits the program (an error is reported ).

The two differences are: if a file is contained, the latter will determine whether it has already been included. if it has already been included, it will no longer contain the file. 1. it can save resources and avoid redefinition errors.

B) include () and include_once ()

It can be placed on the php page before calling the function. When php is executed, it will read the php page introduced by include. If an error occurs, the program will not exit and the execution will continue.

Difference: The former Include includes files, and the latter include_once ()

C) difference between include and require (difference between include_once and require_once)

In the same place: other pages can be introduced.

Difference: if an include error occurs, the program continues to run. if a require error occurs, the program is terminated.

D) which one to use: require_once () is basically used for project creation ()

During php execution, once a function is called, a new stack function will be opened up, which is just a definition. the Function execution rule is as long as you see the function, then php will open up a new stack. the variables in each stack are independent of each other. (Understand global variables and local variables)

There are three tips in PHP:

Notice: note waring: warning error: error

If you do not want to use a variable in a function, or you want to completely stop using a variable, you can use unset (variable name) to destroy the variable. In the php function, we can assign a default value to a parameter. Php uses value transfer by default. if you need to reference (address), use the & variable name. $ A = 1> 2;

$ B =-1> 2;

$ C = 1 <2;

$ D =-1 <2;

Echo "a =".;

?>

Binary: returns two to one. The binary system has only 0, 1 numbers, which is easy to implement electronically. At the same time, a combination of 0 and 1 can represent any number.

Source Code, anti-code, complement:

1 --> source code 00000000 00000000 00000000

A) the highest bit of binary is the sign bit. 0 indicates an integer and 1 indicates a negative number.

B) the original codes, backcodes, and supplementary codes of integers are the same.

C) negative anticode = the original symbol bit of the original code remains unchanged, and other digits are reversed.

-1 --> source code: 10000000 00000000 00000000

Reverse Code: 11111111 11111111 11111111 11111110

Makeup: 11111111 11111111 11111111 11111111

D) complement a negative number = its anticode + 1

E) the decomcodes of 0 and the complement codes are all 0.

F) Php does not have an unsigned number, that is, all inputs in php are signed.

G) during computation on the computer, all computation is performed by code complement. This means that no matter whether a number is a positive number or a negative number, it must be converted into a complement code and then calculated.

Php has four bitwise operations: "bitwise AND &", "bitwise OR |", "bitwise XOR or ^", and "bitwise inversion ~", The calculation rules are as follows:

Bitwise AND &: both are 1, and the result is 1.

Bitwise OR |: one of the two is 1 and the result is 1.

Bitwise OR ^: one of the two is 0, one is 1, and the result is 1.

Bitwise inversion ~ : 0-> 1, 1-> 0

Step: obtain the complement code (because all operations are carried out in the complement method)

~ 2 =? -3

Makeup: 00000000 00000000 00000000 00000010

11111111 11111111 11111111 11111101 (the result is a supplemental Code)-> original code

Reverse Code: 11111111 11111111 11111111 11111100 (first minus 1)

Original Code: 10000000 0000000 0000000 000000011 (-3)

2 & 3: First, find the complement code of 2 and 3 = 2

2's complement: 00000000 00000000 00000000 00000010

3 Complement: 00000000 00000000 00000000 00000011

2 & 3: 00000000 00000000 00000000 00000010

Displacement operation: shifts the left and right of the binary number according to the following rule:

> Shift to the right of arithmetic values: low overflow, the symbol bit remains unchanged, and the symbol bit is used to fill in the overflow high

< <算数左移:符号位不变,低位补0< p>

$ A = 1> 2; $ a = 0

1 complement: 00000000 00000000 00000000 00000001

1> 2: 0000000 000000000 00000000 00000000 (0)

$ B =-1> 2;-1

-1 source code: 10000000 00000000 00000000 00000001

-1 anti-code: 11111111 1111111 1111111 11111110

-1 completion code: 1111111 11111111 11111111 11111111

-1 <2: 1111111 11111111 11111111 11111100

-1> 2: 1111111 11111111 11111111 11111111 (the result is an anti-code)

Reverse Code: 1111111 11111111 11111111 11111110

Original Code: 1000000 0000000 000000000 00000001 (-1)

Array sorting: an array is called an array. it can be used to store multiple data types. Concept

$ Array [0] = 123;

[0] --> subscript, keyword

$ Array [0] --> an element of the array

123 --> value corresponding to the element

$ Array ---> array name

In the php array, the values stored by elements can be of any data type.

$ Arr [true] = "hello"; ==>$ arr [1]

$ Arr [false] = "world" ;=>$ arr [0];

$ Arr [null] = "Beijing" ;=>$ arr [null] or $ arr [""];

If the decimal point is used as the key value, the fractional part is automatically truncated.

We can use print_r to display the array.

PHP arrays can grow dynamically.

$ A = array (2, 3 );

$ A [2] = 56;

Echo $ a [2];

One-dimensional array reference trap: $ arr [bar] = "hello, world ";

Echo $ arr [bar]; (bar will be treated as a constant)

$ A [0] = 1; $ a [1] = 2; $ a [2] = 5;

Count ($ a); = 3

$ A [0] = 1; $ a [5] = 2; $ a [10] = 5;

Count ($ a); = 3

$ Arr = array ();

Echo count ($ arr); = 0

The Unset () function allows you to destroy an element in an array or delete a variable. Note that the keywords of the array are not re-indexed.

?>

By default, the array is passed as a value, not an address. By default, an object is transmitted with an address.

Sort, select sort, insert sort is the process of sorting a group of data in the specified order. Sorting is a basic skill for programmers. Category: a. internal sorting method: loads all data to be processed into the internal memory for sorting. Includes the exchange sorting method (bubble method, quick sorting method), selection sorting method and insert sorting method

B. External sorting method: if the data volume is too large to be fully loaded into the memory, you need to sort it using external memory. Including merge sorting and direct merge sorting.

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.