#PHP Technology and Application
## The first chapter introduces the site
dynamic website Section ###
concept:
Myth: It is not that a site which contain moving images, dynamic effects scrolling map.
Positive Solutions: using database technology to develop websites, content on the page are extracted through a database updated dynamically.
### Section IV environment configuration
integrated environment:
To use the language, you need to match the appropriate development environment, including:
the Apache Web server
MySQL database
PHP language engine
above three modules can be installed separately, making relevant configuration ( manually install relatively complex configuration). Typically use more than three integrated environment for rapid deployment:
WAMP: Window operating system
LAMP: Linux operating system
MAMP: Apple MAC operating system
more than three integrated environments for different operating systems, download and install the development environment has been automatically built a good .
### Operating principle:
GET request: to get data from the server
post request: Submit data to the server
### configuration file:
configuration file is the core of each service, the configuration file is missing or modify the error will cause the service can not function properly
Apache service configuration file: D: \ wamp64 \ bin \ apache \ apache2.4.23 \ conf \ httpd.conf
MySQL server configuration file: D: \ wamp64 \ bin \ MySQL \ mysql5.7.14 \ my.ini
PHP module configuration file: D: \ wamp64 \ bin \ apache \ apache2.4.23 \ bin \ php.ini
Note: configuration file modified , you must restart the service
### wWW directory
www directory in wamp directory is the root directory of the site, all of the files developed, should be placed www directory, localhost access to the local server via browser input
### localhost
local server, wamp installed the software on your computer, both the client and a server, accessed through a browser is your local server, named called localhost
## Chapter PHP language Basics
### Section world the Hello
## # ### PHP tags, comments, data type, data output, coding standard, variables, constants, operators, data type conversion, control statements, arrays, functions
### language tag
<? PHP
......
?>
Note: pure php script file requirements: 1, the beginning of the label shall be written in the first line head. 2, delete the closing tag.
Symbols and Note terminator ###
// single line comment
/ * multi-line comment * /
// English terminator symbol ";"
$ = Hello "Hello World";
### common commands and system functions
echo
echo Output: output only strings, numbers, Boolean (true: 1 false: empty) data type
var_dump
This function displays the configuration information of one or more expressions, including the type and value of the expression. Recursively expand the array values, which are indented by the structure of
** ** Note: When var_dump variables must be present if the value of the variable is present but empty, then no variable returns false, NULL the function returns an output of the feature, so do not add other output functions
requireinclude
1, the require
common with the introduction of important documents, if the introduction of the current failure will directly affect the entire script, introducing the report failed error error
2, Include
common with the introduction of regular files, if introduced will not fail have a greater impact on the current script, the introduction of failure reported Warring error
3, require_once
to avoid duplication introduced, with other rules The require
4, include_once
avoid duplication introduced other rules with the include
header
is used to define the HTTP protocol header information.
Section ### variables and constant
variable
declare variables: $
naming rules: alphanumeric characters and underscores, the first letter is not a number, strictly case-sensitive and can not use the keyword! Recommended hump nomenclature
variables destruction: unset (variable names), the variable is destroyed is released in memory of
the introduction of variable
$ man = 'zhangsan';
$ student = & $ man; // & introduced with
constant:
use the define keyword to define constants, constant name to all uppercase, constant data type can not be a resource object
// define constants
define ( 'SCHOOL', 'Tsinghua University' );
differences in variables and constants of the
difference variable constants
defined $ declarations define () is defined
name must be in upper case sensitive (industry standard)
assignment can not be re-assigned in the assignment
of data type 8 data types can only be a scalar
destroy unset () can not be destroyed destruction
judging method isset () determines whether a defined () determines whether a
scope of local scope global scope
### a third data type
** ** eight kinds of data types
Four scalar types
- Boolean (Boolean)
- shaping (integer) range: 2 ^ 32 or 2 ^ 64 (beyond automatically converted to floating point)
- float (float) range: Double
- string (string)
Two compound types
- type array (Array)
- type objects (object)
two special types
- Resource (Resource)
- type empty (null)
different hexadecimal
$ number1 = 0b10;
$ number2 = 0123;
$ number3 = 0x123;
Object type
single object having certain functions and features, properties and methods of object is a collection of
resource-based
variable may be a folder, a document, obtained from the database the result sets and so on, the operation of this variable is equivalent to the operation of these resources.
NULL type
null data is generally denotes a state variable has no value, expressed in null. The following cases will be null:
directly to a null variable assignment is
used again after a variable destroy the variable
directly using a variable that does not exist
### Section IV data type conversion
automatic type conversion
when the special operation, there will be automatic type with the transition
automatically converted to: false automatically converted to: true automatically converted to: int automatically converted to: string
Shaping: 0 0 Non-integer true: 1 true: "1"
floating point: 0.0 0.00 non-zero floating-point number or false: 0 false: ""
String: '' or '0' is not empty string null: 0 null: " "
array: an array of non-null empty array
null object
unknown variables (variables or destroyed)
cast
changing the original variable type
used setType () function can be cast to a specified variable another type specified
not to change the tag type
format: = new variable (variable type specified) the original variable;
// cast; not to change the variable type
// define a storage variable
$ = Old. 1;
$ new new; // a variable for receiving the converted after
// start conversion
$ = new new (Boolean) Old $; // to true
$ new new = (Integer) $ Old; //. 1
new new = $ (the Float) Old $; // a float. 1
$ new new = (String) Old $; // '. 1'
$ new new = (the Array) Old $; // the Array
$ new new = (Object) $ SUM; // Object
common variable detecting function
function Description
gettype variable type is determined (); returns a boolean, integer, double (float returns "Double"), String, Array, Object, Resource, null, Unknown type
isset () whether a variable the presence of
empty () determines whether a variable is empty (strings, arrays, 0, null)
other types of series variable determination function <br/> isarray (), isbool () , isfloat (), isinteger (), isnull () , isnumberic (), isobjcet () , isrescoure (), istring () and isscalar () if scalar
common math function
function name Description syntax
rand rand ([int, int] ) returns a random integer
mt_rand mt_rand ([int, int] ) using Mersenne Twister algorithm returns a random integer
abs abs (mixe) Returns the absolute value
min min (array) min (mixed , mixed, [, ...]) returns the minimum value
max max ( array) max (mixed, mixed, [, ...]) returns the maximum
round round (float [float [, int [, int]]]) rounded
floor floor (float) truncation of the fractional portion is rounded
ceil ceil (float ) returns a non-zero integer portion of the fractional part is incremented. 1
POW POW (Mixed, Mixed) exp returns the base power value
sqrt sqrt (float) returns the square root
sin sin (float) returns the sine
cos cos (float) returns the cosine
tan tan (float) returns the tangent
deg2rad deg2rad (float) to convert degrees to radians
bindec bindec (string) Binary Coded Decimal
decbin decbin (int) Decimal transfer binary
octdec octdec (string) octal turn decimal
decoct decoct (int) decimal turn octal
hexdec hexdec (string) hex decimal system turn
dechex dechex (string) decimal hex transfected
exp float exp (float arg) returns the value of e power of arg, e is the base of natural logarithms, the value of 2.718282
PI PI a float (void) returns the value for pi
## V string
three definitions ways
single double quotation marks delimiter
parsing of variable support resolve the variable does not support double quotes the same expression
can not be inserted into a single quote into double quote may be inserted into the double and single quotes
Only single quotes and backslash escaping support parsing escape character (\ n \ t \ s, etc.) with the double quotes
$ NUM = 10;
// single quotes
$ title = 'hxsd' $ num.'beijing '.;
// double quotation marks, supporting analytical variables, expressions can not be resolved.
School = $ "<div ID = 'Box'> <h1 of> {$ hxsd} </ h1 of> </ div>";
// delimiter can be named.
str2 = <<< Mark $
<div ID = "Box">
<h1 of calss = "main"> {$ hxsd} </ h1 of>
</ div>
Mark;
// Note ---------- ---------
// delimiter can be used in single and double quotation marks, you can resolve the variable
// string delimiters, and will retain all formatting, eight wide variety of spaces (try to freeze write to avoid the start of the space)
// end tags must be the top grid write
// start after the end tag (the above code "mark") can not have characters such as spaces (including comments statements can not have)
// string fold support OK, pay attention: more than one space will wrap
$ txt = "
Function-
trim () white end to end string is removed and other special symbols or character sequence designated
strtolower () lowercase
the strtoupper () is converted to uppercase
htmlspecialchars () html format string tag in
the strip_tags () function stripped HTML, XML and PHP tag
MD5 () calculated MD5 hash string
strlen () byte length utf8 encoding es: byte character 1: 3 bytes
mb_strlen () number of characters
substr () function string interception (Chinese distortion)
mb_substr () string interception function (not Chinese garbled)
strstr () to find the first occurrence of the string, start capturing all back, and return
strpos (), stripos () Find string in another string for the first time, the position of the last occurrence (not case sensitive)
strrpos (), strripos () ibid (case-sensitive)
flip string
Compare byte string
str_replace () function string replacement
str_repeat () a repeated string
Itrim (), trim (), rtrim () removal of the left sides, the right side of the extra characters (default remove spaces)
Explore ( symbol, string) → array
implode (symbol array) → string array
MD5 (), SHA1 () encrypted string
## VI array
### array type
associative array subscript meaningful string
indexed array, the subscript 0 is the default value starting from
### define an array
defined direct mode assignment
$ a [] = 10;
$ a [] = 20 is;
$ a [ 'name'] = 'John Doe' ;
$ A [ 'Sex'] = 'M';
using array () function
$ B = Array (10,20,30);
$ B = Array ( 'name' => 'John Doe'; 'sex' => 'M'; 'age' => ' 28');
quick assignment
$ c = [10,20,30];
$ c = [ 'name' = > ' John Doe'; 'sex' => 'M'; 'age' => ' 28'];
two-dimensional array with multi-dimensional arrays
// dimensional array
$ = Group Array (
' one '=> array (' John Doe ',' John Doe ',' king five '),
' TWO '=> array (' Zhao six ',' Sun seven ')
);
// define a three-dimensional array
$ class = Array (
'class01' => Array (
'One' => Array ( 'Joe Smith', 'John Doe', 'king five'),
'TWO' => Array ( 'Zhao six', 'Sun seven')
) ,
'class02' => Array (
'One' => Array ( 'Joe Smith', 'John Doe', 'king five'),
'TWO' => Array ( 'Zhao six', 'Sun seven')
)
);
// get Doe
echo calss $ [ 'class02'] [ 'One'] [. 1];
### array traversal
for loop iterates
$ arr = [11,22,33,44,55];
for ($ I = 0; $ I <COUNT ($ ARR); $ I ++) {
var_dump ($ ARR [$ I]);
};
// the foreach
$ f_arr = [ 'name' => 'zhangsan', 'Age '=>' 18 is', 'Sex' => 'm'];
the foreach (Key $ $ f_arr AS => $ value) {
echo $ $ Key value "<br>." ".";.
};
// list (only the index for the array)
list ($ A, $ B, $ C, $ D, $ E) = [ '. 1', '2', '. 3', '. 4', '. 5'];
echp $ a, $ B, $ C, $ D, $ E;
### output array
$ B = 3.1; $ C = TRUE; var_dump ($ B, $ C);
/ * output float (3.1) bool (true) * /
### replication array
$ of arr1 = [111,222,333];
$ = $ arr2 is of arr1; // $ arr2 is a new array
var_dump (== $ $ arr2 is of arr1); // to false
// use &Array references
ARR3 = $ & $ of arr1;
var_dump ($ $ ARR3 === of arr1) to true //
### array of commonly used functions
Function-
array_values () All values in the array into a new array index, and returns
the array_keys () array of all the keys into a new indexed array, and returns
array_reverse () array reversed order
the in_array (element arrays) checking whether there is a value in the array
count () attribute number calculation unit number in the array or object
array_unshift () inserting one or more elements of the array at the beginning of
the array_push () inserting one or more elements of the array at the end
array_unique ( ) removing duplicate values in the array
array_pop () to delete the last element of the array
() delete the beginning of the array elements array_shift
array_splic (array, index number) to delete the specified element (<br/> after deleting elements, rearranges array index, by deleting the index array unset without rearrangement)
Sort () (ascending)
rsort () (descending)
the array_merge () incorporating one or more arrays
### JSON array to a
function described
json_encode (array) JSON format encoding (utf8 encoding parameter must be, otherwise it will give a null character or null)
of json_decode (string, parameters) of JSON format string decoding parameters: <br/> true: returns an array <br/> false: returns the object
## VII operator
type operators
arithmetic operators + - * /%
assignment operator + = = - = * = / =% =. =
Comparison operators>> = <<=! =! == ===
logical operators &&|| not and or
string operators.
Other Operators ternary operator ==:?
Error suppression operator @
elevate the priority symbol ()
# Chapter III process control
## first branch structure
single branch structure
// determine whether or not you look handsome
$ face = 'Shuai ';
// start determination
if ($ face ==' Shuai ') {
echo' you're cool, cool ';
}
bi-branched structure
// start determination
IF (to true) {
echo "OK";
} the else {
echo "NO";
}
multidirectional a branched structure
@ student performance management system
$ score = 100;
/// determines that the student performance score segment
## cyclic structure
while loop
while (conditional expression)
1 + X PHP knowledge
Guess you like
Origin www.cnblogs.com/lijian-cn/p/11941187.html
Ranking