Start My PHP learning Journey

Source: Internet
Author: User
Tags arithmetic operators bitwise bitwise operators decimal to binary http file upload http post logical operators
Lesson Two
LAMP:
Linux
Apache
Ngix
Php
Lesson Three

How to build the server:
1. Integrated installation Environment
XAMPP Package: www.apachefriends.org
2. Separate configuration
Lesson Four

Xampp
Contains a few necessary packages to run the site
1.apache Server
2.PHP Interpreter
3.Mysql Database
Apache:
installation directory for PATH:XAMPP
Catalog: Path/xampp/apache
Mysql:
Catalog: Path/xampp/mysql
Php:
Catalog: path/xampp/php
1.XAMPP Start-up
Exit of 2.XAMPP
3.apache start-Up and shutdown
4.mysql start-Up and shutdown
5. Modify the Apache default port
1. Through the XAMPP panel
2. By changing the configuration file
Lesson Five
PHP Program Writing Rules:
1. php files written in PHP as a suffix
The 2.PHP code must be Between
3. In PHP, each statement must end with a semicolon (the last line statement can not)
Writing rules
2. How to lay out our PHP code
1. Lay out the PHP code in a directory specified in the Apache server, xampp this

The directory of Integrated software is: Path/xampp/htdocs this directory


Usually we have multiple pages on a site, and in order to better manage multiple pages, we usually
Using folders for collation

Folder name: Bdqn_php_basic (project name can be customized)

Path refers to the installation directory of the XAMPP
Attention:
1. The directory of the 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 to our first webpage via http://localhost:80/bdqn_php_basic/first_php.php
The basic principles of PHP Web site operation

1. We created a first_php.php file and wrote a line of PHP code inside the file.

2. We've deployed this first_php.php file to the XAMPP Apache server.

Deployment address: Apache configuration file httpd.conf documentroot in the specified directory

3. Visit in the Browse

Browser and server relationships

b End S End
http://localhost:80/bdqn_php_basic/first_php.php Request-------------------> HTTP protocol
HTTP: Hypertext Transfer Protocol
The client locates the server through the URL (Uniform Resource Locator) (URL)
URLs are called URLs in the HTTP protocol
URL parsing:
Http://www.baidu.com
(The server's Internet address, or domain name)
http://localhost:80/bdqn_php_basic/first_php.php

Third-party presence as next table
Domain IP
Baidu.com 212.21.8.4 (a computer's only IP address on the Internet)

Full URL, should contain port, HTTP protocol default port is 80 port

See if the corresponding port has a corresponding service
Role: Ensure accurate data transfer between HTTP client and HTTP server
Seventh lesson
Chapter II PHP variables and data types

2.1 Lesson PHP Basic Syntax

What is syntax
Language: Human language, before the advent of computer language
In fact the grammar, at the beginning, was used to define the human language

PHP Basic Syntax:
1.PHP code, located in the Between?> and the
2.PHP languages can be embedded in HTML code
3.PHP instruction delimiter; PHP needs to end with a semicolon at the back of each instruction
Java,php,c languages, statements are divided into two types:
1. Process Control Statements:
if () {},while () {},for () {}
2. All function Execution statements
echo ' string ';
SUBSTRING ($str, 0, 3);

Notes for 4.PHP Programs

/* Comment */

/**
* Here's the note
*/
Comments
#注释


5. About the use of whitespace characters in PHP
What are the whitespace characters:
1. Spaces
2.Tab tab
3. Line break

Use: Improve program readability

When to use line breaks:
1. Between two "function execution statements", a line break is required
2. Class person when defining classes (line wrapping required)
...
2.2 Variables and constants for PHP
Role:
A container for temporary storage of data

1. Start with $, followed by the name of the variable
A. Variable names are best seen in the text
Variable names in 2.PHP are case-sensitive

Naming rules for 3.PHP variables
PHP is a weakly typed language, so when we declare variables, we can
Do not specify a data type

PHP Variable rules:
1. The variable starts with a letter or an underscore
2. Variables can only be by letter
3. Cannot use keyword as variable name

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

2. Transfer of variables
2.1 Passing by value
2.2 Reference Delivery

2.3 PHP Data Types-Overview

What is a data type:
is related to a variable and is used to describe the property of a variable

$price
$name

Data type, in PHP, is the type used to describe the value of a variable
Data types that determine how variables are allocated in memory

What is the difference between PHP data types and Java data types?


1.PHP is a weak type of language
$price = 23.5
$name = ' PHP from beginner to proficient '


2. Java Strong data type language
int age = 18;
String name = ' PHP ';
float price = 23.5;

PHP Basic Data type:
Strings: String
Decimals: 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, we do not have the initial time, the system will give it a default value of NULL
Resource type
Example: Connection to a database class (third-party resources)
Callback

2.4 PHP basic data Type-integer (int)

PHP is a weakly typed language

Support for PHP integral type
1. Support for decimal


$age = 18;

2. Support Hex 0-9 A B C D E F


$temp = 0x55ab;

3. Support 8 binary 0-7


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

4. Support for Binary


$temp = 0b101;

What is the maximum supported type in PHP?

Maximum integer: 2^31 4 bytes There is a sign bit
Minimum integer: -2^31-1

Unsigned integers are not supported in PHP

2.5 boolean data structure for PHP

Boolean type is used to store true and false data types

is used to describe a situation where the value of a variable is true or FALSE.

Keyword True,false is case insensitive

3. Usage Scenarios
1. Process Control Statements
if ($is _boy)
{
}


2. Three operator
$a = = $b? ' True ': ' false ';



2.6 PHP Basic Data type----floating-point type

decimal = = floating-point type

The precision of floating-point numbers

10 decimal, converted to 2 decimal point

For example:
10.7
Steps:
1. Convert decimal integer part first
Decimal to binary: In addition to 2 in reverse
-------> 1010
2. Conversion of decimal decimals
Decimal fractional Fractional multiplication 2 take integer part, ordered
0.7------>1 01100 01100 01100 ...
In this case, the computer will be automatically based on the platform and PHP running interpreter, make a fractional reservation yourself


3. Add two parts


10 Decimal, Turn 2 decimal, sometimes cannot use 2 binary
Accurate representation of 10 binary values

Maximum number of floating-point numbers: 1.8e308


2.7 PHP Basic Data type----string

A type used to hold a string:


There are four ways in which you can declare a string in PHP


1. Use the ' declaration '


2. Use the "" Declaration


3.heredoc


4.nowdoc


The difference between single and double quotation marks:




2.8 Conversions between data types

1. Automatic type conversion (program maintenance)
When the program encounters different types, the program will convert automatically, and the conversion relationship is as follows:
Shaping the------string
|
|
|
V

Floating-point "-------Boolean


2. Forced type conversion (program to maintain)
(int)
(string)
(BOOL)
(array)




2.9 PHP Data Type--constants

Constant:
Refers to values that cannot be modified in the execution of a program

Defining constants: Using function define (,)
define (,);
For example
Define (' PI ', 3.1415926)

Determine if a constant is defined: using the function defined ()


Chapter Three Operators of PHP

3.1 Introduction to Operators
Operators supported by PHP
Arithmetic operators: Subtraction

Assignment operators
x = 2; = called operator

Comparison operators
, <,==,,>=,<=

logical operators
&& | | ! OR and

3.2 Assignment operators


Use:
Assigns 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 a decimal is present at both ends of the modulo, it is converted to an integer

If a negative number appears on both ends of the modulo, the result symbol is the same as the first digit symbol after the positive count

Take Counter-

All the operators, his operands, either a variable or an expression

3.4 Comparison Operators
Comparison operator: is the operation to compare the values of two variables

Comparison operator: The result of the final operation is bool type
! = <>!== (not all equals)

= =: Used to compare whether two values are equal

= = = Not only compares the values of two variables, but also compares the address of the variable

Var_dump ($age = = $age 1)//php function, compares the values of two variables, the return value is bool

3.5 Logical operators for PHP
is an operator that judges the logic
Classification of logical operators:
Logic with and
Logical OR OR
Logic is not the opposite
Logical XOR or XOR two comparison value is not the same when it is true

Note: Both ends of the logical operator must be of type bool and, if not, converted to type bool
empty string or ' 0 ' bit false
NULL is also false
The array has no elements and is false when converted to type bool

3.6 PHP Bitwise operators
Bitwise operators:

Principle: Converts integers at both ends of an operator to binary, and then operates on it

3.7 Other operators
Error control Operator: @
Function: Any error messages that may be generated are ignored for temporary suppression of errors
Increment/Decrement operators:
+ +:
Front + +: First assignment, after + +
Post + + +: First + +, post-assignment
--:
Front--: first assignment, then--
Post--: first--, post-assignment
Execute operator: '
function used to execute a command.
$c = ' dir (' c:\\ ');
Echo $c;
String operators:
$a = ' abc ';
$b = ' EFG ';
String connection using the '-' (-) minus sign, cannot use the plus sign
Precedence of the 3.8 operator
Precedence of arithmetic operators: first multiplication, then plus minus
Clone new has the highest priority
Left and right combination of operators
Fourth chapter structure Control of PHP
4.1 Structure Control Overview

1. Machine language 0,1
2. Assembly language
ADD = "+
3. Advanced language
To write programs in a way that is more conducive to human understanding.
Process-oriented language
C language PHP
Object-oriented language
Php,java

Structural Programming:
Structural programming is the software technology that organizes and compiles correct and readable programs according to certain principles and principle.

The view of programming, any program is composed of three basic control structures, order, condition and repetition.
Sequential structure

Select structure

Loop structure

4.2 Program Structure
1. Sequential structure
Sequential execution programs: From left to right, from top to bottom
4.3 Selection structure
PHP selection Structure
1. The simplest conditional statement
4.4 Selection Structure
If
Else
The situation of the second choice
4.5-piece multi-branch case
The header (,,) function sends a custom HTTP message,
For example
Header (' Content-type:text/html;charset=utf-8 ');
charset=gb2312
Charset=gbk
Charset=utf-8
If ElseIf. Else
4.6 Switch Multi-branch
Usage scenario: You need to compare the same variable (or expression) to many different values
and depending on which one it is equal to the relevant operation
4.7 While loop structure
Rand (VAR1,VAR2);
Function Description: Produces a random number, the range of the random number is between VAR1,VAR2
4.10 For Loop
for (;;)
4.11 Foreach Loop
foreach can only be used with objects and arrays, and both syntax
Defining arrays
$test _data = Array (' Apple ', ' banana ', ' orange ', ' tomoto ', ' type ' = ' fruit ');
1. Method One
foreach ($arr as $value)
Iterate over the array above
foreach ($test _data as $item)
2. Method Two
foreach ($arr as $key = $value)
Iterate over the array method above
foreach ($test _data as $key = $value)
echo ' key = ', $key, ', value= ', $value, '
';
The fifth chapter the use of PHP functions

5.1 Basic Introduction to Functions
Fields used by functions
1. Functions in the field of mathematics
2. Functions of the computer domain: a fixed program segment, or a subroutine, used to implement a fixed function
Implement a fixed program segment or function
Features of the function:
1. Reuse code, reduce unnecessary, repeat the code, improve the reusability of the program

5.2 Definition and classification of functions and advantages
Definition of a function
function Fun_name ()
{
Code
}
Classification of PHP functions
System functions:
PHP language implements its own good function: ABS (), main (), sort ()

Custom functions:

Advantages of the function:
1. Re-usability of the Code
2. Reduce the complexity of the code
3. Avoid the impact of program changes
4. Encapsulation (algorithm, data structure)

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


function Func_name (paramters) {
code block
}

customizing functions and making Calls

Considerations for defining functions:

1. Defining a function must use the keyword: function
2. Naming rules for function names and naming rules for variables are consistent with each other, and the function's
The name is not case-sensitive
3.


5.4 Parameter passing of PHP functions
What is the function of the parameter:
Pass external values, variables to inside of function

Parameters are related to the body of a function: the number of parameters, and the need for parameters that are not required by the business logic parameter is the origin of the decision
, usually because the external data needs to be used in the code (the function body), the external value is passed to the function body using the parameter

Parameter: is the entrance to the function
Return value: Is the exit of the function, you can use return; return function

Classification of function parameter passing:
1. Normal parameter passing: that is, the value is passed
Max_define (17,19);

$a = n; $b = 19;
Max_define ($a, $b);

2. Passing by reference: changing variables outside the function
passing function definitions by reference

Max_redefine (& $a,& $b);

5.5 Scope of PHP variables
Scope: Refers to the life cycle of a variable, relative to the memory


Variable to have memory space to store the value of the variable
1. Variable Scope classification in PHP
1. Local Variables
Variables defined inside the function
2. Global variables
is defined directly in the PHP file (not in the function body, class properties, methods)

3. Super Global variables
The life cycle already exists at the beginning of the PHP program.
$_get---HTTP GET variables
$_post---HTTP POST variables
$_files---HTTP file upload variables

Summarize:
Local variables have the shortest life cycle and exist only in code blocks

Use global variables: $a global;

2. Use global variables in functions to declare with the keyword global

function Test_area ()
{
$c = 8;

Global $a, $b;
echo $a, $b;
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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