PHP php from Beginner to proficient (a)--want to learn PHP's small partner benefits come!

Source: Internet
Author: User
Tags arithmetic operators bitwise bitwise operators constant definition getting started with php php language learn php php class

PHP from Mastery to getting started

(i) Introduction and basic knowledge of PHP

   PHP (foreign name: Php:hypertext Preprocessor, Chinese name: "HypertextPreprocessor") is a commonOpen Sourcescripting language。GrammarAbsorbed theC language、JavaAndPerlFeatures that are conducive to learning, useBroad, mainly applicable toWebDevelopment areas. PHP's uniqueGrammarMixed upC、Java、PerlAndPHPSelf-created grammar. It can be better thanCGIOrPerlPerform more quicklyDynamic Web pages。 Made with PHP.Dynamic Pageswith otherProgramming LanguagesComparedPHPis toprogramembedded inHTML(Standard Universal Markup LanguageThe next application) in the document to execute, the execution efficiency than the fully generatedHTMLof the tagCGImuch higher; PHP can also performcompilingAfter the code, the compilation can be achievedEncryptAndOptimizedThe code runs so that the code runs faster.

first, let's get some basic knowledge about PHP

"Static website and dynamic website"
1, Static website: (Pure HTML page, the page fixed, will not change), no interaction with the background server, no database support;
2, Dynamic website: (can dynamically display different content according to the interactive situation), need to interact with the background server, need database support.
"Support for dynamic website language"
Java----->jsp
PHP----->php
ASP----->asp

"Common Servers"
Apache: A Apache company's servers, used to parse the PHP class website;
Tomcat: Apache Company's other server, used to parse the JS-type website;


"Common Database"
MySQL, Access, Oracle, SQL Server ...
Our PHP is generally used in conjunction with MySQL. Of course, PHP can connect to almost any major database.

"b/s C/S"
b/S structure: (browser/server, browser/server mode). Users only need to access the Web site through the browser, most of the operation function is centralized in the background server.
c/S structure: Client/server structure is the client and server structure. The user needs to install the client. The client can share certain operation functions.

"Common Development PHP Integration Environment"
wamp:windows+apache+mysql+php;
lamp:linux+apache+mysql+php;
Phpstudy:
Phpserver:
PHP developed the preferred Linux system, but PHP can be friendly compatible with various operating systems (Windows,linux,macos, Unix ...) ;

Getting Started with PHP

"Types of PHP tags"
PHP files, if you use PHP syntax, you must put the PHP language into the markup. PHP supports the following four ways of marking:
①<?php?> This is the official PHP recommendation, which is our main use of the wording! This tag can be inserted anywhere in the HTML document;
>>> NOTE!!! : If the page has only PHP language, it is recommended to omit the end tag?>
Reason: Space section ...
②<script language= "php" ></script> long notation: Always available, however, we do not recommend it.
③<?? > Short marking notation. The default does not turn on, you need to modify the php.ini file "Short_open_tag=on" open. However, because of conflicts with HTML tags, it is not recommended.
④<%%>asp style, default does not open, need to modify php.ini file "Asp-tag = on" open, but with the asp,jsp in the flag conflict, not recommended

"Instruction delimiter in PHP;"
1, the "Structure definition statement" in PHP (branch, loop, class, function, etc. with {}), do not need to end with a semicolon.
2. The "Function execution statement" in PHP, (without the end of {}), must end with a semicolon.
3, Special case: End the last statement before the label?>, you can omit the semicolon.


Single-line Comment
/*
* Multi-line Comment
*/
/**
* Documentation Comments
*/

#脚本注释

"Variables in PHP"
The variables in ①php, declared and used, must start with $.
②php is a weakly typed language in which variables do not need to be declared and can be assigned any type of value directly;
③php can be used to declare multiple variables at the same time using a hyphen. You cannot use commas to separate them.
Eg: $num 1= $num 2= $num 3=5;
④ Common variable functions:
unset (): Delete and release the variable;
Isset (): Detects whether the variable is set;
Empty (): detects if the variable is empty (not set or null is empty);
The name of the ⑤ variable: Only alphanumeric underscores can be made, starting with numbers. And, the variables in PHP are case-sensitive!!
$name, $Nnme, $NAME are different variables;
However, PHP's built-in functions are case-insensitive! echo Echo is valid.


"Variable Type in PHP"
①php supports 8 types of data:
4 Scalar types: bool Boolean integer floating-point float/double string
2 composite types: Arrays Array Objects Object
2 Special types: resource resource null.
② shaping ranges from -2^32~-2^32-1, beyond this range, and automatically to floating-point types.

"The situation in PHP is FALSE!!!" 】
1, Boolean false
2, Shaping 0
3. Float type 0.0
4, string "" "0" ("0.0" "0000" are all pairs)
5. Empty array
6. Empty objects are counted as false only in the PHP4 version, and other versions are true.
7, NULL, and variables that have not been defined
8, all resources are counted right!! (except for PHP4, all objects are counted)

"Declaration of strings in PHP"
PHP supports 3 ways of declaring strings:
① ': Single quote execution is more efficient (subtle) if you don't need to parse the variable
② "": customary more commonly used
③<<< (delimiter): $str =<<<s (bound identifier)
Bound Identifier declaration string, starting with <<< (bound identifier)
End of bound identifier encountered!!! Not even a single space in front of it!
The bounding identifier can be any letter, and you only need to keep the start and end consistent.
S
④ three ways to differentiate:
A: The delimiter function defaults to the same as double quotes. Double quotation marks can be placed in the delimiter.
B: The variable cannot be parsed in single quotation marks. Both quotation marks and delimiters can parse variables.
Note: When parsing variables in double quotes, the variable names should be separated by spaces, and the {} is recommended to wrap them up.
C: Each quotation mark can be applied to each other, but cannot put the same quotation marks as itself.
D: In single quotes, you cannot use escape characters (except for ' itself, escape character \ itself '), and you can use escape characters in double quotes.

"Pseudo-type in PHP"
Pseudo-type: Not a real data type, it exists just to tell the programmer what type of data it can be. Often used when composing help documents:
Mixed: representative parameters can be a variety of data types;
Number: The parameter can be either integer or float;
Callback: The delegate parameter can be a callback function;



"Data type conversion in PHP"
1. Automatic type conversion: The Boolean, Null, String, and other types are automatically converted to an integer or float type when the operation is expressed.
Null-->0
True-->1
False-->0
String--> the number before the value is not converted to 0
2. Coercion of type conversions: Forces variables to be converted to other types of variables according to our needs;
① use () to declare a new type of strong turn;
② use Settype (); function strong turn;
BOOL Settype (mixed var,string type); The first parameter represents any type of variable, the second argument represents the data type of the string type, and a Boolean result is returned.
③ Two ways of difference:
The first ① is to assign the converted result to a new variable;
②, directly modifies the data type of the original variable;
$ New variable = (new type) $ original variable;
New type, you can use full spelling, or you can use abbreviations
(int), (integer)-Converted to integral type
(bool), (Boolean)-converted to Boolean
(float), (double), (real)-converts to floating-point type
(string)-converts to a string
(array)-Convert an array
(object)-Convert to Object

BOOL Settype (mixed var,string type)
"Test function for PHP judgment variable type"
Is_bool (): Determines whether it is a Boolean type
Is_int (), Is_integer (), and Is_long (): Determines whether it is an integral type.
Is_float (), is_double (), and Is_real (): Determines whether it is a floating-point type
Is_string (): Determines whether it is a string
Is_array (): Determines whether the array
Is_object (): Determines whether the object
Is_resource (): Determines whether the resource type
Is_null (): Determines whether it is null
Is_scalar (): Determines whether it is a scalar
Is_numeric (): Determines whether it is any type of numeric and numeric string
Is_callable (): Determine if the function name is valid


"Output Statements in PHP"
echo "..."; the value of the output variable.
Var_dump (num); The data type and value of the output variable [and some other information].
Print_r (); specifically for printing arrays.

"Definitions and use of constants in PHP"
1, the definition of the constant: bool Define (string constant name, mixed any type of constant value [, BOOL is case-sensitive]);
2, the constant note:
The ① constant definition can only use the Define () function;
② constant names, which in principle require the use of uppercase declarations. and must not use the $ declaration ($ can only be a variable);
After the ③ constant declaration, the default global scope is valid and there is no scope to say.
④ constants can not be changed, and can not be deleted! Functions such as Unset,settype are not valid.
⑤ constants are case-sensitive by default, but you can change the third parameter of the Define function to True when you declare a constant, instead of case-insensitive.
⑥ constants must be defined with define () before they can be used. If an undeclared constant is used, the default is to a constant string. However, the warning will be reported!
Var_dump (num); ———— >string "num"
The value of the ⑦ constant can only be a scalar boolean, String, Integer, float.
3, you can use constant ("") to read the constant value, no eggs!
You can use Get_defined_constants () to get the defined constants! Contains the system custom N multiple constants.

<?PHPHeader("content-type:text/html; Charset=utf-8 "); $num=1; $num= "Haha"; Echo $num; $num 1=$num 2=$num 3=5; Echo $num 1; Echo isset($num 1); Var_dump(Empty($num 1)); $isTrue=""; if($isTrue){        Echo"This is true"; }Else{        Echo"This is false"; }        Echo"<br/><br/><br/>"; $str 1= ' hahah{$num 1}hahah\ ' AH1 '; Echo $str 1; $str 2= "hahahhah{$num 1}ahah2 "; Echo $str 2; $STR 3=<<<Str123 456 789str; Echo $STR 3; functionfunc1 () {Define("NUM", 12,true);    } func1 (); Echo"<pre>"; Print_r(get_defined_constants()); Echo"</pre>"; #var_dump (num);    

Operators in PHP

operator
1. Arithmetic operators:
+,-,*,/,%,++,--
2. Assignment operators:
= + = = *=/=%=. = (Connection string)
3. Comparison operators:
< > <= >= = = = = = = = = = =!==
= =: Requires equal value, without requiring equal data type;
= = = The required data types are equal;
! =: Compare values only, with values equal to false;
!==: Comparison value and type, both equal to false;
4. Logical operators:
and/&& or/| | not/! XOR (different OR)

&& | | A short circuit occurs when the operation is performed, and the right side is no longer executed when the left side is judged (&& false on the left side of the result; | | True on the left, the result is true)
XOR: Logical XOR. The result of only one pair on either side is true;
5, Bitwise operators: convert 10 binary to 2, and then perform the operation.
&: Bitwise AND. After turning into 2, two are 1 and the result is 1. eg:12&12-->1100&1100=1100=>12;
|: Bitwise OR. After turning into binary, there is a 1, which is 1;
^: Bitwise XOR. After turning into 2, the two are not identical to 1, both are 0 or both are 1, the result is 0;
~: After the bitwise inversion into 2, all digits are reversed and then converted to 10 output (!!!!! Law: ~n-->-(N+1))
&LT;&LT: Shift left: After turning to binary, move left several, the right number of spare digits 0. (!!!! Rule: num<<n-->num*2^n)
&GT;&GT: Bitwise RIGHT SHIFT: After turning to binary, right shift several, left spare position number 0. (!!!! Rule: num>>n-->num/2^n)

6. "Other operators"
?:: Expression 1? expression 2: Expression 3: Expression 1 establishes execution expression 2, otherwise executes 3.
': The calling system is the command line in the environment and executes, but because of security and cross-platform, we do not advocate the use of: eg: ' ipconfig '
@: Error Message control. can temporarily block out some small error messages. But it is not advocated!
=>: array subscript pointing
->: Object

"Mutable variables"
In front of a variable name, add a $ symbol. You can use the value of the first variable as the name of the new variable.
$hello = "Hello1";
$ $hello = "world";//$hello 1
$$ $hello = "Liu";//$world

&: Address symbol. The variable name is added to the & symbol, which takes the reference address of the current variable (the address of the variable in memory).
$num 2=& $num 1;//out the address of NUM1 to num2, which is equivalent to the reference data type we are referring to. The values of num2 and NUM1 will change at the same time.

in PHP, the exchange of A and B is implemented using code$a=10; $b=8; #intellectual disability Level    $c=$a; $a=$b; $b=$c; #Mortal Class    $a=$a+$b; $b=$a-$b; $a=$a-$b; #Neural Level    $a=$a^$b; $b=$a^$b;//$a ^ $b ^ $b    $a=$a^$b;//$a ^ $b ^ $a    /** Analysis: * 8-------00001000 *------00001010 * ^-------00000010*/        Echo $a.",".$b;

branching and looping structures in PHP

"Branching structure in PHP"
If the judging condition: see 02;
elseif:php in ElseIf statements can be ligatures, can also be written separately;
The switch structure in the switch:php is determined by a loose comparison (= =) and different from JS!!!!!
>>> Note: In PHP, continue can be used with the switch structure, with the same effect as break!
PHP continue and break can be followed by numbers, which means skipping several layers of loops or switch. For example: Break 3 means termination 3 has been looped
Do-while: Loop Finally, must add; semicolon.
>>>eg:do{}while ();

The specific structure can be broadly refer to the Bo master before sharing the JS loop.


"Process Control Statement"
1. Break: Terminates the loop of this layer; A number can be followed by a break, which means terminating several layers of loop break 3; Terminating a 3-layer loop
2, continue: skip this cycle; Continue can be followed by numbers, which means skipping several layers of loops
3, return: The End Function, and return the value (if any), but only in the function can be used, the script does not recommend the use of return
4, exit (mixed concluding)/die (mixed concluding) function: Directly end the current PHP script! If a parameter is passed in, the closing is printed first, and then the current script is ended.

//Use the branch loop structure to implement the table and fill in the specified numbers. Echo"<table style= ' width:500px;  border:1; Border-collapse:collapse; ' > ';  for($i= 0;$i<10;$i++){        if($i%2!=0){            Echo"<tr bgcolor= ' Red ' >"; }Else{            Echo"<tr bgcolor= ' green ' >"; }         for($j= 0;$j<10;$j++){            Echo"<td style= ' border:1px solid black ';>"; Echo $i.$j; Echo"</td>"; }        Echo"</tr>"; }    Echo"</table>";

Share this issue here, I think the content of the small partners to recommend, Welcome to comment below the comment area and Bo master interaction, thank you!

Not to be finished, to be continued ...

PHP php from Beginner to proficient (a)--want to learn PHP's small partner benefits come!

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.