PHP Basic Notes

Source: Internet
Author: User
Tags bitwise type null domain name server nginx server
Requirements:

Organize the knowledge points into the blog park each knowledge point to be equipped with code testing, and the code is to knock out alone. Organize your code into documents for installation configuration operations.

Hanshunping recommended

Study the Linux kernel

Research algorithms

Research Network Technology (network management, cyber security)

Research Database

PHP notes. PHP is currently managed by Zend Company, MySQL (mysql->sun->oracle) (LAMP) cross-platform, while supporting a variety of databases, high efficiency, with good security. free to use; Open source code (Learn someone else's code); PHP4,PHP5 begins support for object-oriented weak data types Web site: A Web site is a collection of multiple Web resources. Simply put, the Web application can be understood as a directory on the hard disk, which is used to manage multiple Web resources. Web sites are often referred to as Web sites or Web projects/projects.

PHP Basic concept PHP is PERSONLA homepage currently managed by Zend Company PHP embedded into HTML code, PHP script runs on the server side 1994 (php1.0), 1995 (php2.0), 1997 (php3.0), 2000 ( php4.0), php5.0 Php6.0 added: Better support for web2.0, more support for better Unicode support, increased object-oriented programming support, XML programming support, SOAP (Simple Object Protocol)

L There is a very important principle in software development: the compilation environment and the running environment should be consistent.

L Data first on the official website, more English site

b/S and C/s comparison development cost is low, management and maintenance is simple, the product upgrade is convenient, the training cost for users is low, the user is easy to use, the probability of failure is small; The client cannot change itself and is restricted by the browser. Learn what to send and receive. Tools: HttpWatch lighttpd server, nginx server Apache manual Management Apache, managed by command line: httpd K Start[shutdown|restart] httpd.conf Apache directory structure Apache Server

Bin: This directory is used to store commands commonly used by Apache, such as Httpd,apachemonitor

Cgi-bin: This directory holds common commands under Linux. sh

CONF: Store configuration file httpd.conf

Error: Bad record

Htdocs: The folder where our site is stored (by default), if you have multiple sites, you can sort them by folder

Icons: Store icon

Logs: Record Apache related logs

Manual: Manual

Modules:apahche Module

Apache will read httpd.conf on startup, load related modules

Operating mechanism diagram

Mpm:mutil processing module multiple processing modules

APR: Portable Runtime Library

Apache Life cycle Configuration Virtual directory

We put the web app in Apache's default Hdocs directory, and Apache will manage it automatically.

L Add Virtual directory node

#欢迎页面

DirectoryIndex index.html index.htm,index.php

#站点别名

Alias/myblog "D:/myblog"

#访问权限设置

Order Allow,deny

Allow from all

L Note documentroot "D:/phpenv/apache/htdocs"

10. Access Rights settings

#表示对d盘下面的myblog文件设置权限设置

#表示先许可所有的ip访问, deny means deny all IP access, first look at allow and see deny

Order Allow,deny

#先看看allow

Allow from all

Case

#先看deny再看allow, the settings in Allow Override the Deny

Order Deny,allow

Allow from 218.20.253.2

#218.20 The IP that starts is rejected

Deny from 218.20

11. Setting up a virtual host

L Enable httpd-vhosts.conf: Add in httpd.conf file

Include

L Configure a virtual host in \extra\httpd-vhosts.conf

#这里配置欢迎首页面

DirectoryIndex index.html index.htm index.php

Options FollowSymLinks

#不许可别人修改我们的页面

AllowOverride None

#设置访问权限

Order Allow,deny

Allow from all

L Modify Hosts file, speak www.sohu.com Redirect to local page

Practice:

Configure a www.sohu.cn virtual host (a Web site, site) in the httpd.conf file, and then register the www.sohu.cn host in the window System

Enable httpd-vhosts.conf in the httpd.conf file to log off the #

Include conf/extra/httpd-vhosts.conf

Suppose our virtual host is in C:\myweb (i.e. a website)

Setting up the http-vhosts.conf file

Add our IP and host mapping relationships in the Hosts file: c:/windows/system32/drivers/etc/hosts

(Think of the hosts domain name configuration public network IP and intranet IP)

Create a name called Itcast site in the root directory of the virtual host, create a index.html page under the app, and map the Web app to the default Web app, index.html page set as the homepage of the web App

• The process of accessing the Web page

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

1) Resolve host www.sohu.com

2) Query The local Hosts file: windows/sys32/drivers/. /hosts (ip127.0.0.1 corresponding domain name)

3) If the local hosts file does not find IP, the IP domain name to DNS (domain name server)

4) Locate the IP

5) Send HTTP request package

6) Apache Parse HTTP request Package: Resolve host, resolve site name, resolve resource Name

7) Access to resources

12. Configure Apache to support PHP (Apache will not process PHP by default)

Kit software: AppServer or WMAP. The software packs the environment we need to install

PHP and Apache Integration (that allows Apache to handle PHP):

#让apache载入php处理模块

LoadModule php5_module ~php Installation path/php5apache2_2.dll

#phpinidir这个用于指定php的ini文件,

Phpinidir "~php Module Installation Path"

#这个配置表示, when a resource is *.php, it is handled by PHP.

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

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

Specify extension path in php.ini extension_dir=~php installation path/ext (there are many function libraries, form libraries, database libraries, etc.), specify the extension library path of PHP

Let PHP support MySQL feature: Enable Php_mysql in php.ini

If it does not start, an error will be found without the relevant function.

Install MySQL

Install phpMyAdmin (phpMyAdmin is a site, so directly extracted to the site root directory)

Install and configure the Discuz forum

1) Prepare a discuz forum code

2) Unzip it to the root directory of the Web site

3) Copy the Discuz upload file to the Discuz folder

4) Modify config.inc.php. Database configuration, and an administrator $forumfounders= ' admin

5) Visit Http://localhost/discuz '

Complete the configuration: There are multiple sites on a single server, and each site is configured with a domain name

Solution 1:

1) differentiate different sites by port: Be prepared to bind to a site

Modify httpd.conf to enable virtual host configuration; Configure the httpd-vhosts.conf file; In the Hosts file, add the corresponding relationship between the IP and the domain name;

Also add a new domain name to the IP binding

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

Let Apache listen on port 81: Add a listen 81

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

Browser Access www.***.com:81

Solution 2:

Differentiate different domains by ServerName port

To add a configuration to the httpd-vhosts.conf file:

ServerName www.***.com

DirectoryIndex news.html

PHP variables (note that data and variable concepts are not the same) PHP variables are defined in terms of $, the data type of the PHP variable is changed, and the data type of the PHP variable is determined by the context of the runtime. PHP is a weak data type programming language (data types do not wander) PHP basic data type: integer, decimal (floating point) float/double (PHP does not differentiate between single and double), Boolean type Boolean, String type

PHP Composite types: Array of arrays, objects (object)

PHP Special data types: null, Resource Type (Resource): $conn =mysql_connect ("localhost", "root", "root");

$a = 890;

Var_dump ($a);

$a = 1.1;

Var_dump ($a);

?>

Detail discussion of integral type

A) octal: $a = 0123;, hex $a=0xah;

b) PHP does not support unsigned integers, that is, the integer in PHP is a signed number. Typically takes up to 4 bytes. We can display our own machines through php_int_size, an integer expressed in a few bytes. echo php_int_size; maximum integer echo Php_int_max, if exceeded, the shape is automatically converted to float; (The maximum minimum value needs to be sorted)

c) If a given number exceeds the range of integers, it will be interpreted as float

Thinking about practical problems:

$a;

If only $ A is written, but no value is assigned

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

Echo $a;

?>

Code considerations: Robustness, extensibility, security, code efficiency (concurrency, efficiency) discussion of the details of the Boolean type

A) True,false are case insensitive

b) The following values will be treated as false:

A Boolean value of false itself

Integer value 0

Floating-point value 0.0

An empty string, and the string "0"

An array that does not include any elements

Objects that do not include any member variables

Special type null (including variables that have not been set)

Floating-point Details

A) floating-point numbers (also called double or real numbers), the precision of floating-point numbers is 14 (starting from the left, the first non-0 is the beginning of precision; $a =0.23456789022222988; $b = 0.00002222233334444;

b) The length of the floating-point number is relative to the platform, usually the maximum is 1.8e308 and has a precision of 14 decimal digits (this restriction is important)

String details

A) a character occupies one byte; $a = "Hello"; occupies 5 bytes

b) Theoretically, there is no limit to the size of the string, that is, the memory can be

c) When we define a string, we can use single quotation marks or double quotation marks, the difference is as follows: Double quotation marks will interpret the value of the variable. If the string is enclosed in single quotation marks, the other rules are the same except that the \ "output \" is processed.

When a variable is contained in the "" number, its value is output, and the character contained in the "sign" is the output of its characters.

Automatic conversion of PHP character types

The type of the variable is not set by the programmer, rather, it is determined by the context in which PHP is used according to the variable, and can be passed Var_dump ($ variable 1,$ variable 2 ...) Mode to display its type. (PHP does not need to be compiled to run)

Ten. PHP Constants

A) There is no dollar sign in front of the constant $

b) Constants are defined by the Define () function or const, but not by an assignment statement, which is required to assign an initial value at the time of definition; the name of the constant, usually all uppercase, and then the underscore interval;

Define ("Tax_rate", 0.08); In the program we do not want a value to change, consider using constants, such as pi, tax rate ....

Const tax_rate=0.08;

c) Constants can be defined and accessed anywhere, regardless of the scope of the variable;

D) Constants cannot be redefined or undefined once defined;

e) The value of the constant is the scalar "base data type:"

11. Expressions

Expressions are the most important cornerstone of PHP. In PHP, almost anything written is an expression.

The so-called expression is anything that has value. $a =7/3; How to save decimal place to 2 bits (function processing)

Comparison operators: $a = = = $b congruent $a!== $b non-congruent (values are equal and the types are the same)

$a! = $b only values that are not equal are true

$a!== $b as long as the values are not equal, or if the types are not equal, true

String operator (.): When two basic data types are used to connect, it means that their contents are stitched together as strings.

Type operator: instanceof is used to determine whether a PHP variable belongs to an instance of a class class. It is not possible to determine whether it belongs to the base data type.

The data types that can be used by switch can be: Reshape, Decimal, String, Boolean, null. From our learning if and switch branches, if is often the interpretation of a range, and switch is the judgment of a point.

PHP function Basic concept: A set of program directives (statements) that perform a function. In PHP, functions are divided into: custom functions, System functions (provided by the PHP statement itself, functions that can be used directly, PHP designers think, in the process of project development, many people will use some features). Basic structure of the function:

Function name (parameter ... ){

function body

return value, (Can not)

}

The arguments to a function can be multiple, and the data type is any type supported by the PHP language; the name of the function is the same as a custom variable, and the first letter can only start with a _,a-z,a-z, not a number or a special character.

Pages in PHP call each other

A) require () and require_once ()

Generally placed in the top of the PHP page, before PHP execution, the first read into the require contains the page, in the event of an error, then quit the program (error).

The two differences are that the previous encounter is the include file, the latter will determine whether it has already been included, if it is included, no longer contain the file. One can save resources while avoiding redefining errors.

b) include () and include_once ()

Can be placed in the PHP page before the call function, when PHP is executed, will not be read into the introduction of the PHP page, if an error occurs, the program will not quit, continue to execute.

Difference: The former include encounters the containing file, the latter include_once ()

c) Include and require differences (simultaneous include_once and require_once differences)

The same place: all the other pages can be introduced

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

d) which to use: When doing the project, basically using require_once ()

When PHP executes, once it encounters a function call, it will open up a new stack function just a definition, the rule of function execution is that whenever you see a function, PHP will open up a new stack the variables between the stacks are independent of each other. (Understanding global variables, local variables)

There are three types of tips in PHP:

Notice: Note waring: Warning Error: Wrong

If in a function we don't want to use a variable, or if we want to completely stop using a variable, you can use unset (the variable name) to destroy the variable. In the PHP function, we can assign a default value to a parameter. PHP defaults to a value pass, and if you need to pass a reference (address), use the & variable name. $a =1>>2;

$b =-1>>2;

$c =1<<2;

$d =-1<<2;

Echo "A=". A;

?>

Binary: every two into one. Using binary only 0, 12 numbers, simple and easy to implement in electronic way. At the same time, a combination of 0,1 can represent any number.

Original code, anti-code, complement:

1--> Original Code 00000000 00000000 00000000 00000001

A) the highest bit of binary is the sign bit: 0 for integers, 1 for negative numbers

b) The original code of the integer, anti-code, the same complement

c) Negative number of the anti-code = Its original code of the symbol bit unchanged, the other bits take the reverse

-1--The original code: 10000000 00000000 00000000 00000001

Reverse code: 11111111 11111111 11111111 11111110

Complement: 11111111 11111111 11111111 11111111

D) The complement of negative number = Its anti-code +1

E) 0 of the anti-code, the complement is 0

f) PHP does not have an unsigned number saying that: The output in PHP is signed

g) In the computer operation, all in a complementary way to calculate. It means that no matter whether a number is positive or negative, it must be turned into a complement and then calculated.

There are 4 bit operations in PHP, namely "Bitwise AND &", "Bitwise OR |", "bitwise XOR", "bitwise negation ~", and the operation rules are as follows:

Bitwise AND &: Two bits are all 1 and the result is 1

Bitwise OR |: Two bits have one of 1 and result is 1

Bitwise XOR ^: two-bit one is 0, one is 1, and the result is 1

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

Step: Find the complement (because all operations are performed in a complementary fashion)

~2=? -3

Complement: 00000000 00000000 00000000 00000010

11111111 11111111 11111111 11111101 (result is complement), original code

Anti-code: 11111111 11111111 11111111 11111100 (first minus 1)

Original code: 10000000 0000000 0000000 000000011 (-3)

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

2 Complement: 00000000 00000000 00000000 00000010

3 Complement: 00000000 00000000 00000000 00000011

2&3:00000000 00000000 00000000 00000010

Displacement operation: To move the binary number to the left and right, the operation rule is:

>> Arithmetic right shift: low overflow, sign bit invariant, and sign bit fill overflow high

<<>< p=""> <>

$a =1>>2; $a =0

1 Complement: 00000000 00000000 00000000 00000001

1>>2:0000000 000000000 00000000 00000000 (0)

$b =-1>>2; -1

-1 of the original code: 10000000 00000000 00000000 00000001

-1 Anti-code: 11111111 1111111 1111111 11111110

-1 Complement: 1111111 11111111 11111111 11111111

-1<<2:1111111 11111111 11111111 11111100

-1>>2:1111111 11111111 11111111 11111111 (Result is anti-code)

Reverse code: 1111111 11111111 11111111 11111110

Original code: 1000000 0000000 000000000 00000001 (-1)

Array sorting find out why arrays: data types that can be used to hold multiple data, which we call arrays. Concept

$array [0]=123;

[0]--> Subscript, Keywords

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

123---elements corresponding values

$array---> Array names

In the PHP array, the value that the element holds can be any data type.

$arr [true]= "Hello"; ==> $arr [1]

$arr [false]= "World";==> $arr [0];

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

If you make a key value with decimals, the fractional part is automatically truncated.

We can use Print_r to display an array of cases.

The array of PHP can be dynamically grown.

$a = array (2,3);

$a [2]=56;

Echo $a [2];

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

Echo$arr[bar];(will treat bar 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 you can delete a variable, but be aware that the array's keywords are not re-indexed.

?>

The array is passed by default as a value, not an address. An object is passed an address by default.

sorting, selecting sorting, inserting sort sorting is the process of arranging a set of data in a specified order. Sorting is a programmer's basic skill. Category: A. Internal sorting: All data that needs to be processed is loaded into the internal memory for sorting. Including the Exchange sorting method (bubbling method, fast sorting method), the selective sorting method and the insertion type sorting method

B. External sorting: The amount of data is too large to load into memory and needs to be sorted with external memory. Includes the merge sort and the direct merge sort method.

  • 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.