Start my PHP learning journey

Source: Internet
Author: User
Tags decimal to binary http file upload variable scope
Start lesson 2 on my PHP learning journey
LAMP:
Linux
Apache
Ngix
PHP
Lesson 3

Server construction method:
1. integrated installation environment
XAMPP software package: www.apachefriends.org
2. separate configuration
Lesson 4

XAMPP
Includes several required kits for running the website
1. apache server
2. PHP interpreter
3. Mysql database
Apache:
Path: installation directory of xampp
Directory: path/xampp/apache
Mysql:
Directory: path/xampp/mysql
PHP:
Directory: path/xampp/php
1. XAMPP startup
2. exit XAMPP
3. apache startup and shutdown
4. mysql startup and shutdown
5. modify the default port of apache
1. use the xampp panel
2. change the configuration file
Lesson 5
PHP programming rules:
1. Compile the php file with php as the suffix
2. PHP code must be included in Between
3. in PHP, each statement must end with a semicolon (the last statement can be left blank)
Writing Rules
2. how to arrange our PHP code
1. deploy the PHP code to a directory specified by the apache server.

The Directory of the integrated software is: path/xampp/htdocs


Generally, a website has multiple webpages. to better manage multiple webpages, we usually
Use folders for classification

Folder name: bdqn_php_basic (the project name can be customized)

Path indicates the installation directory of xampp.
Note:
1. the directory for program deployment is defined by the apache configuration file.

Configuration File: apache/conf/httpd. conf
Configuration options: DocumentRoot "D:/xampp_2/htdocs"

DocumentRoot "D:/xampp/htdocs"


Access our first webpage through http: // localhost: 80/bdqn_php_basic/first_php.php
Lecture 6: basic principles of PHP website operation

1. we created a first_php.php file and wrote a line of PHP code in the file.

2. we deployed the first_php.php file to the xampp apache server.

Deployment address: directory specified by DocumentRoot in the apache configuration file httpd. conf

3. access in browsing

Relationship between browsers and servers

B-end S-end
Http: // localhost: 80/bdqn_php_basic/first_php.php request ---------------> http protocol
HTTP: Hypertext Transfer Protocol
The client finds
A url is called a URL in the HTTP protocol.
URL parsing:
Http://www.baidu.com
(The Internet address of the server, that is, the domain name)
Http: // localhost: 80/bdqn_php_basic/first_php.php

The third party has the following table:
Domain name IP address
Baidu.com 212.21.8.4 (the unique IP address of a computer on the Internet)

The complete URL should contain the port. the default http port is port 80.

Check whether the corresponding port has the corresponding service
Purpose: ensure that data is transmitted accurately between the http client and the http server.
Lesson 7
Chapter 2 PHP variables and data types

2.1 Course PHP Basic syntax

What is syntax?
Language: human language, early in the emergence of computer language
In fact, at the beginning, the syntax was used to define the human language.

Basic PHP syntax:
1. PHP code, located in And?> Between
2. PHP can be embedded into HTML code.
3. PHP command separator; PHP needs to end with a semicolon after each command
Java, php, C language, and statements are divided into two types:
1. process control statement:
If () {}, while () {}, (){}
2. all function execution statements
Echo 'string ';
Substring ($ str, 0, 3 );

4. PHP program Comments

/* Comment */

/**
* Comments here
*/
// Comment
# Note


5. use of blank characters in PHP
Blank space characters:
1. space
2. Tab
3. linefeed

Use: improve program readability

When to use line breaks:
1. line feed is required between two "function execution statements ".
2. class Person (line feed required) when defining classes)
...
2.2 PHP variables and constants
Purpose:
Container for temporary data storage

1. start with $, followed by the variable name
A. for variable names, see wenzhiyi
2. variable names in PHP are case sensitive.

3. naming rules for PHP variables
PHP is a weak language, so we can
Data type not specified

PHP variable rules:
1. variables start with letters or underscores
2. variables can only be letters
3. Keywords cannot be used as variable names

1. variable definition
1.1 Definition of traditional variables
1.2 Definition of variable

2. Transfer of variables
2.1 pass by value
2.2 reference transfer

2.3 PHP Data types-overview

What is data type:
Is used to describe the attributes of a variable.

$ Price
$ Name

Data type. in PHP, it is the type used to describe the value of a variable.
The data type determines the way variables are allocated in the memory.

What is the difference between the data type of PHP and that of JAVA?


1. PHP is a weak language.
$ Price = 23.5
$ Name = 'php from entry to Master'


2. JAVA strong data type language
Int age = 18;
String name = 'php ';
Float price = 23.5;

PHP basic data type:
String: string
Decimal: faloat
Integer: int
Logical type: boolean

Composite type
Array: // store the name of a series of books array ()
Object:

Special data types:
NULL: When a variable is defined, the system will give it a default value of NULL.
Resource type
For example, database connections (third-party resources)
Callback

2.4 PHP basic data type-integer (int)

PHP is a weak language

PHP Integer support
1. supports decimal


$ Age = 18;

2. supports hexadecimal 0-9 A B C D E F


$ Temp = 0x55AB;

3. 8-digit 0-7 supported


$ Temp = 0755 ==========> 7*8 ^ 2 + 5*8 ^ 1 + 5*8 ^ 0

4. binary supported


$ Temp = 0b101;

What is the maximum supported type in PHP?

Maximum integer: 2 ^ 31 4 bytes with one symbol bit
Minimum integer:-2 ^ 31-1

PHP does not support unsigned integers

2.5 PHP Boolean data structure

Boolean is a data type used to store true and false data.

Is used to describe whether the variable value is true or false.

The keywords true and false are case insensitive.

3. Use cases
1. process control statements
If ($ is_boy)
{
}


2. three operators
$ A = $ B? 'True': 'false ';



2.6 basic PHP Data type-floating point type

Decimal = floating point type

Floating point precision

The problem of converting decimal places to binary decimal places

For example:
10.7
Steps:
1. first convert the decimal integer part
// Convert decimal to binary: except for 2, the remainder is obtained in reverse order.
10 -------> 1010
2. convert the decimal part.
// Multiply the decimal part by 2 and take the integer part for ordered sorting
0.7 ------> 1 01100 01100 01100...
Here, the computer will automatically retain the decimal number based on the interpreter running on the platform and PHP.


3. add two parts


Decimal decimal, sometimes it is not allowed to use binary decimal
Accurately represents the decimal value

Maximum floating point number: 1.8e308


2.7 PHP basic data type ---- string

A type used to save strings:


There are four methods to declare a string in PHP


1. use ''to declare


2. use the "" statement


3. heredoc


4. nowdoc


Difference between single quotes and double quotes:




2.8 conversions between data types

1. automatic type conversion (program maintenance)
The program automatically converts different types of data. the conversion relationship is as follows:
Integer ------ string
|
|
|
V

Floating point type ------- boolean


2. Force type conversion (program maintenance)
(Int)
(String)
(Bool)
(Array)




2.9 PHP Data type-constant

Constant:
Indicates the value that cannot be modified during program execution.

Define constants: Use the define (,) function (,)
Define (,);
For example
Define ('pi ', 3.1415926)

Determine whether a constant is defined: Use the defined () function ()


Chapter 3 PHP operators

3.1 Introduction to operators
Operators supported by PHP
Arithmetic operator: addition, subtraction, multiplication, division

Value assignment operator
X = 2; = is called an operator.

Comparison Operators
>,<,==,>=, <=

Logical operators
& |! Or and

3.2 value assignment operator


Usage:
Assign a value to another variable.


3.3PHP operator-arithmetic operator


+
-
*
/: 3/2 = 1.5
%:
When both ends of the modulo are positive integers, the operation is the same as the calculation.
If decimal places exist at both ends of the modulo, the result is converted to an integer.

If there is a negative number at both ends of the modulo, calculate the positive number first, so that the result symbol is the same as the first number symbol.

Reverse-

All operators, their operation objects, are either a variable or an expression.

3.4 Comparison operators
Comparison operator: This operator is used to compare the values of two variables.

Comparison operator: The final calculation result is of the bool type.
! = <>! = (Not all equal)

=: Used to compare whether two values are equal

===: Not only compare the values of two variables, but also compare the addresses of variables

Var_dump ($ age = $ age1) // a php function that compares the values of two variables. the returned value is bool.

3.5 PHP logical operators
Is an operator used to judge the logic.
Classification of logical operators:
Logic and
Logical OR
Logic is not the opposite
True when the values of logical differences or xor comparison are different

Note: both ends of the logical operator must be of the bool type. if it is not of the type, it will be converted to the bool type.
Null string or '0' bit false
NULL is false.
Array does not contain elements. it is also false when converted to the bool type.

3.6 PHP bit operators
Bitwise operator:

Principle: convert the integers at both ends of the operator to binary, and then operate on it

3.7 Other operators
Error Control Operator :@
Purpose: all possible error messages are ignored for temporary error suppression.
Increment/decrease operator:
++:
Front ++: assign values first, and then ++
Post ++: first ++, and then assign a value
--:
Front --: assign values first, then --
Post --: first --, and then assign a value
Execution operator :''
Used to execute commands
$ C = 'dir ('C :\\')';
Echo $ c;
String operator:
$ A = 'abc ';
$ B = 'efg ';
The string connection uses '-' (-) minus sign, and the plus sign cannot be used.
3.8 operator priority
Arithmetic operator priority: First multiplication and division, then addition and subtraction
Clone new has the highest priority
Combination of left and right operators
Chapter 4 structure control of PHP
4.1 Structure Control Overview

1. machine language 0, 1
2. assembly language
ADD = "+
3. advanced language
Write programs in a way that is easier for humans to understand
Process-Oriented Language
C language PHP
Object-oriented language
PHP, JAVA

STRUCTURE program design:
Structural programming is a software technology that organizes and compiles correct and easy-to-read programs according to certain principles and principles.

From the perspective of programming, any program consists of only three basic control structures: sequence, condition, and repetition.
Sequential structure

Select structure

Loop structure

4.2 program structure
1. ordered structure
Sequential execution program: from left to right, from top to bottom
4.3 select structure
PHP selection structure
1. the simplest condition statement
4.4 select structure
If
Else
Either case
4.5 multi-branch condition
Header (,) sends a custom http packet,
For example
Header ('content-Type: text/html; charset = utf-8 ');
CHARSET = gb2312
Charset = gbk
Charset = utf-8
If elseif... else
4.6 switch multiple branches
Scenario: compare the same variable (or expression) with many different values.
And perform related operations based on which one it is equal
4.7 while loop structure
Rand (var1, var2 );
Function description: generates a random number ranging from var1 to var2.
4.10 for loop
For (;;)
4.11 foreach loop
Foreach can only be used for objects and arrays.
Define an array
$ Test_data = array ('apple', 'banana ', 'Orange', 'tomoto ', 'type' => 'fruit ');
1. Method 1
Foreach ($ arr as $ value)
Traverse the above array
Foreach ($ test_data as $ item)
2. Method 2
Foreach ($ arr as $ key => $ value)
Traverse the array method above
Foreach ($ test_data as $ key => $ value)
Echo 'key = ', $ key,', value = ', $ value ,'
';
Chapter 5 Use of PHP functions

5.1 Basic Introduction to functions
Areas of function use
1. functions in mathematics
2. functions in the computer field: a fixed program segment, or a subroutine, used to implement fixed functions.
Implement fixed program segments or functions
Features:
1. reuse code to reduce unnecessary and repetitive code writing and improve the reusability of the program

5.2 function definition, classification, and advantages
Function definition
Function fun_name ()
{
// Code
}
PHP Function Classification
System functions:
Functions implemented by PHP: abs (), main (), sort ()

Custom functions:

Advantages of functions:
1. increase code reusability
2. reduced code complexity
3. avoid the impact of program changes
4. encapsulation (algorithm and data structure)

5.3 User-defined functions
How to declare and define a function
Syntax rules:


Function func_name (paramters ){
// Code block
}

Customize the function and call it

Precautions for defining functions:

1. keywords must be used to define a function: function
2. the naming rules of function names are consistent with those of variables.
Is case insensitive.
3.


5.4 passing parameters of PHP functions
What is the role of a parameter:
Pass external values and variables to the function

Parameters are related to the function body: the number of parameters, and whether or not parameters are required depends on the origin of the business logic parameters.
Generally, the parameter is used to pass external values to the function body only when external data is required in the code (function body ).

Parameter: the function entry.
Return value: the exit of the function. return can be used.

Classification of function parameter transfer:
1. common parameter transfer: value transfer
Max_define (17,19 );

$ A = 17; $ B = 19;
Max_define ($ a, $ B );

2. pass by reference: change the variable outside the function
Transfer function definitions by reference

Max_redefine (& $ a, & $ B );

5.5 PHP variable scope
Scope: refers to the lifecycle of a variable, relative to the memory


The variable must have the memory space to store the variable value.
1. classification of variable scopes in PHP
1. local variables
Variables defined in the function
2. global variables
It is defined directly in the PHP file (not in the function body, class attributes, and methods)

3. Super global variables
The lifecycle already exists at the beginning of the PHP program.
$ _ GET --- http get variable
$ _ POST --- http post variable
$ _ FILES --- HTTP file Upload variable

Summary:
The life cycle of local variables is the shortest and only exists in the code block.

Use global variables: global $;

2. to use global variables in a function, use the global keyword for declaration.

Function test_area ()
{
$ C = 8;

Global $ a, $ B;
Echo $ a, $ B;
}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.