First stage PHP basics. Math, character libraries and loops

Source: Internet
Author: User
Tags php basics

A beginner of PHP's accompanying notes, record their growth!

I. Mathematical function library
1. Installation: Math library is part of Phpcore

2.
(1) Floor: Rounding Down
(2) Ceil: Rounding up
(3) Round: Rounding
int round (number $var [, int $percision])
(4) POW: exponentiation
(5) Sqrt: Ask Open square
(6) Max: Ask for maximum value
(7) Min: To find the minimum value
(8) Rand: seeking integer random number
(9) Mt_rand: Finding a better random number of integers

Two. Process Control statement--cycle
1. When to use loops: repetitive things with loops, regular things
With loops
2.for Cycle
for (EXPR1;EXPR2;EXPR3) {
...
}
Description
(1) Expr1: Unconditional execution once, general to the variable assignment
Initial value
(2) EXPR2: Statements executed in each loop, function
Determine the condition of the loop entry (end condition of the loop)
(3) EXPR3: After each loop (the last statement executed in the loop body)
The statements that are executed, the increment or decrement of the action control variable,
That is, step
Special usage of 3.for loops
(1) Omitting an expression in for
for (;;) {
...
}
(2) Each expression in the For loop can have more than one statement, and
Separated by commas

Description
A. The first expression and the third expression can have
More than one statement

B. Second expression, only the last expression is executed
So I usually write only one statement

4. Break, use of continue
Description
A. Break is used in switch, loop,
End Program Execution (loop over a layer of loops)
B.continue is used only in loops, jumping out of the current loop
The following code (skipping a loop), and then to the next
Loop (the second expression is true)

5. While, Do...while loop
(1)
while (condition) {
...
}
do{
...
}while (condition)

Description
A. For, while judgment after execution
Do...while first execution after judgment

B. For, while at least 0 execution
Do...while perform at least 1
(The first condition is false do...while
Execute once more than while)
C. General For,while can be exchanged,
The exact number of loops is generally for many,
While cannot loop in number of times

Three. Character function library
1. Install: Character library is Phpcore component, do not install
2.
(1) substr: Character intercept function
Format: String substr (String $var,
int $start [, int $length])

Description
A. $start: string start number, numbering starting from 0
B. $length: Intercept string Lengths
C. If you omit $length, intercept the letter from the beginning until
End of string
D. Returns false when the starting number is greater than the string length
E. $start, $length if negative, the position is reciprocal

(2) Strip_tags: Clear html or PHP tags

(3)
Strtolower: Convert Letters to lowercase
Strtoupper: Convert Letters to uppercase
Ucfirst: Capitalize the first letter
Ucwords: Capitalize the first letter of each word

(4)
Trim: Clears the spaces on either side, or clears the specified characters
LTrim: Clears the left space, or clears the specified character
RTrim: Clears the right space, or clears the specified character

(5)
Strpos: Gets the substring in the string where the first occurrence of the numbering position,
Numbering starting from 0, case sensitive
int Strpos (string $var, string $sub [, int $offset])
Stripos: Gets the substring in the string where the first occurrence of the numbering position,
Numbering starting from 0, case insensitive
Strrpos: Gets the substring that appears in the string at the last numbered position,
Numbering starting from 0, case sensitive
Strripos: Gets the substring that appears in the string at the last numbered position,
Numbering starting from 0, case insensitive

(6)
STRSTR: Get substring first occurrence in string
Character to string end, case-sensitive

STRISTR: Get substring first occurrence in string
Character to string end, case insensitive
STRCHR: is strstr alias
STRRCHR: Gets the substring that appears last in the string
Character to string end, case-sensitive

(7) Strlen: Get string length

(8) Strrev: string reversal
(9) Str_replace: String substitution
String Str_replace ($search, $replace, $var)

(10)
Htmlspecialchars: Converting special symbols to HTML entities

Htmlspecialchars (String $var [, $flag =ent_compat])

Description
A. can only convert > < ' "& special characters
B. $flag can be omitted, the default value Ent_compat does not handle single quotes
C. $flag:
Ent_compat: Single quotation marks are not processed
Ent_quotes: Handling single and double quotation marks
Ent_noquotes: Do not handle single and double quotes

(11) Cryptographic functions
MD5: Get hash value, return 32 bits
SHA1: Get hash value, return 40 bits



















First stage PHP basics. Math, character libraries and loops

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.