PHP Individual Knowledge points

Source: Internet
Author: User

Web introduction of the development

Web development is divided into

1, static Web development (HTML page);

If one of our pages, is always static, then it is still web development, the general use of HTML technology can do;

Static Web Resource development technology: HTML;

2, such as: we need to post, online payment, send text messages, e-mail ... This requires dynamic Web technology;

The web represents the meaning of the Web page, which is used to represent the resources that the Internet host is accessing to the outside world, that is, resources for browser access, which are divided into:

Static Web resources: (such as HTML pages) refers to the data that people view in a Web page is always the same;

Dynamic Web resources: refers to the Web page for people to browse the data is generated by the program, different times to access the Web page to see the content is not the same

Of

Commonly used dynamic Web resources development technology PHP, Jsp/servlet, ASP, ASP, and so on CGI Universal Gateway technology;

Web site: Also called Web resource, Project. is a folder in the Web server Htdocs directory, a Web site contains resources can be: php,css,html,jsp, pictures, videos ...

with UML flowchart to explain PHP process of File Execution


Write and debug Simple PHP code

Introduction to basic syntax of PHP

①php can be associated with HTML Code Blending

You can also embed HTML code in PHP

<body>

<?php

Echo "Hello,world"

?>

</body>

can also embed PHP code (script) using the following methods " This method is not recommended "

<body>

<script language= "PHP" >

Echo "<br/> Test it! ”

?>

</script>

</body>

If you just want to display the value of a variable , you can also write this:

//<?= variable?>

④/ notes:

C-style single-line comment

*unix Style single-line comment

Php the variables and basic syntax

1. Variables/Constants

2. PHP data type and basic syntax

Basic syntax

1, HTML and PHP mixed

2. End of a statement with; (semicolon)

3, how to define a variable, and the use of variables

4. The data type of the variable is not invariant

5. PHP is a weak data type programming language

6, PHP case-sensitive

7. A valid variable name begins with a letter or underscore followed by any number of letters, numbers, or underscores (do not start with a number or start with a special character)

There are three main categories of PHP data types :

1 , Php Basic data Types

① Integral type Integar

Can represent an integer such as: $ts =1; $ts =-12

② floating point type (decimal type: Includes single-double precision float/double)

can represent a decimal number such as: $ts =1.12; $ts =3.1415926

③ Boolean type (denotes true and false null and Faule)

True or False For example: $ts =true; $ts =false

④ String Type

Represents a string such as: $ts = "I am a good man, hello"

2 , composite data types

① Arrays (Array)

② Objects (object)

3 , special data types

①null (empty type)

② resource Type (Resource)

Define a variable and assign a value to a variable

/<?php

$a =90;//here is the equivalent of defining a variable A and assigning a value of 90, if the re-assignment will replace the previous value and type, and so on, so that the previous value is flushed out, or a variable is redefined

/?>

? Think of a question, what will it output

(Note the difference between notice and fatal warming, the former skips in memory, executes the following, while the latter is a fatal error, the program jumps directly, completely no longer executed)

<var_dump ($a) the data type used to output the variable a

<?php

$a;/If you define a variable without assigning a value, it will not be allocated memory in memory

Echo $a;

Echo "HELLO";

?>

(HTML interface display:notice:undefined var ...) The back of the hello still can be output

<!--code robustness, scalability, security, efficiency (concurrency, speed)--

the details of the integer data :

The ① value can be decimal, hexadecimal (ox-preceded), or octal representation;

For example: $a =0123;//octal number (starting with 0)

The binary is converted into decimal:

0123=3*8 's 0-time Square +2*8 +1*8 of two square +0*8 three-time Square =83

Other analogy ...

$a =0x1a;//hexadecimal number 0~9,a,b,c,d,e,f A total of 16 digits to indicate

0X1A=A*16 's 0-time Square +1*16 +x*16 of two square +0*16 three-time Square =26

②php does not support unsigned integers, that is, integers in PHP are signed;

The word length of the ③ integer is related to the platform, usually (4 bytes signed). The word length of an integer value can be represented by a constant php_int_size, and the maximum value can be represented by a constant php_int_max;

④ if a given number exceeds the range of an integer, it will be interpreted as float, (an integer typically occupies four bytes (in the case of the peace table) with a byte of 8bite;0 as an integer, 1 as a negative, and a positive int with a maximum of 2 31 minus one or 2147183647. The negative int is the maximum of 2147183647, which is more than the value of which the data type becomes a floating-point number.

details of the Boolean type: true and the false

$a =true; $a =false;

The following values will be treated as false:

The Boolean value false itself;

Integer value 0 (0);

Floating-point value 0.0 (0);

An empty string, and the string "0";

An array that does not enclose any elements;

Objects that do not include any member variables (php4.0 only);

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

SimpleXML generated from an XML document without any tags (tags)

All other values are considered true (including any resources)

Floating-point Details

① floating-point numbers are also called double-precision numbers or real numbers;

The length of the ② floating-point number is related to the platform, usually the maximum value is 1.8e308, and has the precision of 14 decimal digits (this restriction is important); the precision of floating-point numbers is 14 bits, and the first non-0 book from the left is the beginning of precision.

If $a=0.234567890222229888, then the output is 0. 0.23456789022223, rounding after 14 bits, output 2.3456789022+e8 if $a=0.000000023456789022

456.123456789238 output 456.12345678924;

The details of the string

① A string consists of a series of characters, a character that occupies a byte $a= "Hello", then $ A takes up 5 bytes

② how large a string can be represented? PHP restrictions on the length of the string is only related to the size of the computer running the PHP program, that is, PHP string can be large enough, the theory is that we have no limit to the size of the string, as long as not more than memory;

1) When we define a string, we can use a single quotation mark ' or double quotation mark ', the difference:

Example:

$a = 90;

$user 1= "hello$a";(double quotes)

$user 2= ' hello$a '; (single quotes)

Echo ' user1= ' user1;

Echo ' user2= ' user2;

Then the output is user1=hello90 user2=hello$a

As we can see from the above case, when a variable is contained in "", it is assumed that the output is its value, and that the single quotation mark is the output of a $ A symbol itself;

2) $v 1= "hello\" ";(double quotes)

$v 2= ' hello\ '; (single quote)

Echo ' v1 ';

Echo ' v2 '

The output is Hello hello\ "

Summary: If the string is enclosed in single quotation marks, other rules are the same except that it will output \ When it is processed.

Php automatic conversion of data types

The type of the variable is not set by the programmer, specifically, is determined by the context in which PHP is used according to the variable, and can be Var_dump ($ variable 1,$ variable 2 ...). ) In a way that displays its type.

An expression

Almost anything written is an expression, but the simplest and most precise way to define an expression is "anything that has value."

Arithmetic operators

Commonly used in PHP are: + 、-、 *,/,% (modulo, get the remainder)

Left +-*/% a+=3 equivalent to a=a+3 other in turn

comparison Operators

$a = = $b equals True if $ A equals $b

$a = = = $b Congruent true if $ A equals $b, and their type is the same

$a! = $b Unequal to True if $ A is not equal to $b

$a <> $b True if $ A is not equal to $b

$a!== $b non-congruent true if $ A equals $b, or their type is not the same

$a < $b less than true if $ A is strictly less than $b

$a > $b greater than True if $ A is strictly greater than $b

$a <= $b less than or equal to true if $ A is less than or equal to $b

$a >= $b greater than or equal to true if $ A is greater than or equal to $b

logical Operators

$a && $b and logic and true if $ A and $b are true

$a | | $b or logic, or true if $ A and $b any one, the result is true

! $a not logical not if $ A is not true, the result is true

Ternary operators

Basic syntax:

Expression 1? Expression 2: Expression 3

Rule: If the operation result of expression 1 is true, take the value of expression 2, otherwise take the value of expression 3, the expression 2,3 can be a specific value or a formula or function.

String operators

There are 2 string operators, using the Join operator ("." ), a small dot.

<?php

$a =hello;

$b =world;

$c = $a. $b;

Echo $c;

?>

Then output: Hello World

“.” Both sides, regardless of whether it is a string, as long as "." will be processed by the type of the string, and their contents are stitched up.

type operator

Basic syntax: instanceof is used to determine whether a PHP variable belongs to an instance of a class, and in actual development we may need to determine whether a variable is a type, which is often used in object-oriented development. "The back is fine."

precedence level of operators  

rank from low to high  

PHP Individual Knowledge points

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.