PHP Web Base
I. Static website & 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 for data, need database support.
Second, support the language of the dynamic website
Java---JSP
PHP----PHP
ASP----ASP
Third, the common server
Apache:apache Company's servers for parsing PHP-like websites
Another server under the Tomcat:apache company, used to parse the JSP class website;
Iv. Common Database
Mysql,access,oracle,sqlserver ...
We php generally match MySQL usage. Of course, PHP can connect to almost any major database.
V. B/s C/s
b/S: Browser/server structure. A Web site that users only need to access via a browser. Most of the operation functions are centralized in the background server.
C/S: Client/server structure. The user needs to install the program that the client uses. The client can share certain operation functions.
Vi. Common development of PHP integration environment
Install a software, built in a variety of development needs of the software or language environment
wamp:windows+apache+mysql+php
lamp:linux+apache+mysql+php
Phpstudy:
APPServer:
>>>php developed the preferred Linux system, but PHP is compatible with a variety of operating systems.
(Windows,linux,unix,macos ...)
Basics of getting Started with PHP
**php "+" only operation function, no connection function. Connection function with "." Connection
* * Keywords: Types of PHP tags, instruction separators in PHP, variables in PHP, false in PHP, declaration of strings in PHP, pseudo types in PHP, data type conversions in PHP, type of judgment in PHP, output in PHP, and constants in PHP
I. Types of PHP tags
PHP file, if you want to use PHP syntax, you must put the PHP language into the markup. PHP supports the following four kinds of marking methods;
①<?php?>
This is the official PHP recommendation of the wording, but also our main use of the wording! This tag can be inserted anywhere in the HTML document;
>>> Note: If the page has only PHP language, the recommended ellipsis end is '?> '.
Cause: If you include the end symbol, you may import the last extra line of the file when you import the PHP file.
②<script language= "PHP" ></script>
Long marking notation. This kind of writing can always be used, but we do not recommend it.
③<?>
Short mark style. The default does not turn on, you need to modify the php.ini file "Short_open_tag = on" open.
However, because of conflicts with tags in XML, it is not recommended.
④<%%>
ASA style. The default does not turn on, you need to modify the php.ini file "asp_tags = on" open. However, it is not recommended because of conflicts with tags in asp,jsp.
Second, the instruction delimiter in PHP
1, the "Structure definition statement" in PHP (branch, loop, class, function, etc. {} end), do not need to use a semicolon end.
2, the "function execution statement" in PHP, without the end of {}, must use the end of a semicolon.
3, Special case: End the last statement before the label?>, you can omit the semicolon.
Third, the variables in PHP
1, the variables in PHP, declaration and use, must start with $.
2, PHP is a weak type of language, variables do not need to declare, you can directly assign any type of variable
3, PHP can be used to declare multiple variables at the same time, but not separated by commas; eg: $num 1 = $num 2 = $num 3 = 5;
4. Common variable functions:
Unset (); Delete and release variables;
Isset (); Check whether the variable is set;
Empty (); Verify that the variable is null (not set or null is empty);
5, the name of the variable: can only be composed of numbers, letters, underscores, the beginning can not be a number. Also, variables in PHP are case-sensitive! $name $Name $NAME are different variables! However, PHP built-in functions or class names are case-insensitive! echo Echo is all valid!
6. Data type in PHP (8 types)
>>>4 Types of scalar :
Boolean Type: Boolean
Integral type: integer
Floating point type: float/double
Strings: String
>>>2 Types of composite :
Arrays: Array
Objects: Object
>>>2 Types of special :
Resources: Resource
Null: null
7, the scope of the integral type: -2^31~ (2^31-1), over this range, automatic to floating-point type
Iv. cases in PHP that are counted as false
1, Boolan false
2, Shaping 0
3. Float type 0.0
4, the string "" "0" ("0.0" "000" are counted right! Only one 0 is wrong! )
5. Empty array
6. Empty objects are counted as false only in PHP4. Other versions, objects are counted true.
7, NULL, and undefined variables;
8, all resources are counted right! ( except PHP4, all objects are counted!!!) )
V. Declaration of strings in PHP
PHP supports three ways of declaring strings:
1, ":
2, "":
3. <<< (delimiter):
$str = <<<s (bound identifier)
Delimiter declaration string, starting with <<< (bound identifier)
Encounter shelf bound identifier end!! A space can not have!!
The bounding identifier can be any letter, just make sure the start and end are consistent!
s; (bound identifier of shelf)
4. The difference between three ways of declaring:
① delimiter function, the default is the same as double quotation marks. (But you can put double quotes in the delimiter)
In ② single quotes, variables cannot be parsed, and double quotes, delimiters can parse variables.
Note: When parsing variables in double quotes, be aware that the variable name needs to be "hahaha{$num}hahaha" "Hahaha${num}hahaha"!
Double quotation marks can be placed in ③ single quotes, and single quotes can be placed in double quotation marks. But you cannot put quotation marks of the same type.
Escape characters cannot be used in ④ single quotes (except for the single quotation mark ' itself, the escape character \ itself), and the escape characters can be used in double quotes.
Vi. pseudo-Types in PHP
Pseudo-type: Not a real data type. It exists just to tell the programmer which type of data is available, and which types are often used when composing help documents.
Mixed: The delegate parameter can be a variety of different data types.
Number: The parameter can be either integer or float.
Callback: The delegate parameter can be a callback function.
Vii. data type conversions in PHP
1, automatic type conversion: When the operation is expressed, boolean,null,string and other types, will be automatically converted to an integer or float type
Null-->0
True-->1
False-->0
String to a number before a numeric character,
If not, switch to 0 "123a"-->123 "A123"-->0
2, coercion type conversion: According to our needs, forcing the variable to other types of variables.
$ New variable = (new type) $ original variable; $str = (String) 1;
New type, you can use full spelling, or you can use abbreviations. Integer/int Boolean/bool is OK.
The types that can be cast are as follows:
① use () to declare a new type of strong turn:
(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
② using Settype (); function Strong turn:
BOOL SetType (mixed var,string type); The first parameter represents a variable of any type, the second parameter represents the data type of the string type, and returns a Boolean result.
③ differences between the two types of conversions:
①: It is to assign the result after conversion to a new variable;
Section ②: Directly modifies the data type of the original variable.
Viii. types of Judgments in PHP
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
Ix. output Statements in PHP
echo "..."; the value of the output variable
Var_dump (num); Data type & value of output variable [& some additional information]
Print_r (arr); specifically for printing arrays
Single-line Comment
/*
* Multi-line Comment
*/
/**
* Documentation Comments
*/
# Script Comments
#echo "① form";
Ten, constants in PHP
1, the definition of the constant: bool Define (String constant name, mixed constant value [, BOOL is case-sensitive]);
2, the constant note:
① constants are defined, only the Define () function can be used;
② constant names, which in principle require the use of uppercase declarations. and must not carry the $ symbol ($ can only be a variable);
After the ③ constant is declared, the default global scope is valid. There's no scope to say.
④ constants can not be changed, and can not be deleted! Unset,settype and other functions are invalid
⑤ constants are case-sensitive by default!!! However, when you declare a constant, you can change the Define third argument to true to be case insensitive.
⑥ constants must be defined with define () before they can be used. If you use an undeclared constant, the default is to a constant string. However, there will be warnings.
Var_dump (num);-->string "Num"
The value of the ⑦ constant can only be a scalar boolean String Float Integer
3, you can use Echo constant ("NUM"); Read the constant value! Attention!!!
You can use Get_defined_constants () to get all the defined constants!! Includes system-customized n-Multiple constants
PHP basic knowledge is always