Concept to fill a vacancy
DRY principle: do not repeat yourself minimize duplication.
Syntactic sugar (Syntactic sugar), also translated as icing grammar, syntax refers to some kind of computer languages being added, the grammar of the language does not affect the function, but more programmers to use. In general, the use of syntactic sugar can increase the readability of the program, the program code to reduce the chance of error.
constant
define (name, value); name can be either uppercase or lowercase.
1. Data Type: three categories, eight kinds of data types
---
- Scalar quantity
- Integer
- Float does not distinguish between single and double precision type -PHP
- String - at utf-8 encoded character, a Chinese character equals three characters in the string issues on multivariate analysis can be used to distinguish {} isolation
of some string manipulation functions:
1.1 substr (String, Start, End); interception string.
1.2 strpos (string, the string to search for); find the location of the first occurrence of the string.
1.3 strrpos (string, the string you want to find); find the location of the last occurrence of the string.
1.4 trim (string, optional parameters); first remove spaces or special characters.
1.5 strtoupper () strtolower () string case conversion.
1.6 ucwords (string); the word capitalized.
1.7 str_replace (search, replace, subject ); replacing the matched contents.
1.8 gzcompress (string); string compression. gzuncompress (string); decompressed string. - boolean
- Hybrid
- Array: keys, also known as subscript. In the nominal integer is the index array, a string for the next nominal associative array, as an integer plus a nominal mixed string array. Adding value is not the subject of time, will add a 1 in front of the largest index. If the array level too, use var_dump not display properly, you can use
echo '<pre>'
print_r () print displays
ecoh '</ pre>'
The reason that the array is a hybrid, because its value can be an integer, string and so mixed.
Is defined as an array of popular $ a = []; instead of a conventional array $ a = array ();
some common functions array
array_push ($ a, 'hello' ); // add array element behind
array_unshift ($ a, 'nihao'); // add elements in front of the array
array_pop ($ a); // delete the rearmost element of the array
array_shift ($ a); // delete a preceding array element
explode (delimiter, string); string divided
implode (glue, pieces); composition string - Objects
- Array: keys, also known as subscript. In the nominal integer is the index array, a string for the next nominal associative array, as an integer plus a nominal mixed string array. Adding value is not the subject of time, will add a 1 in front of the largest index. If the array level too, use var_dump not display properly, you can use
- Special type
- Resources
$ A = the fopen ( 'dadada.php', 'W');
var_dump ($ A);
returns a resource type is Empty
use var_dump to see empty type, you see only a null, because null values are empty and the type of
a variable in php unassigned defaults to null;
value after unset are null;Type Conversion
- Resources
- is_ series
php is weakly typed, automatic type conversions can occur
Translation
You can convert a special character as an ordinary character, but also can convert ordinary characters as special characters.
html access in writing some php
<?php $a=true; ?>
<?php if($a){?>
I am real
<?php }else{?>
hello every
<?php }?>
<?php if($a):?>
correct
Incorrect
<?php endif;?>
<?php for($i=0;$i<10;$i++):?>
<?php echo $i.'
';?>
<?php endfor;?>The difference between include and include_once
How many times is displayed include the introduction of many times, include_once introduction of how many times a side that displayed once, checks whether the introduction of introduction.
Detecting the value of the variable is set
isset ()
function: to determine whether the current variable assignment- Return Value: If you have already assigned returns true, whether it is an integer, string, returns true
- If no value or variable does not exist, or a variable value is null, returns to false
empty ()
action, it is judged whether or not the current variable is null - If you do not return the assignment or variable does not exist true
If variable assignment, the empty string is an integer of 0 string, floating point 0.0, false, there is null (empty), an empty array. The result is empty.
Extension: boolean if () {} is determined statements 1 and 0 represent the true and false.Data validation, some methods fast write interface
// Check to pass over the post data
IF (filter_has_var (INPUT_POST, 'EMAIL1')) {
echo "Data found";
} the else {
echo 'NO Data';
}
// verify mailbox
if (isset ($ _ POST [ ' In email '])) {
// verify the contents of the mailbox
iF (the filter_input (INPUT_POST,' In email ', FILTER_VALIDATE_EMAIL)) {
echo "legitimate mail";
} the else {
echo' mailbox is not valid ";
}}
FILTER_VALIDATE_BOOLEAN
FILTER_VALIDATE_EMAIL
FILTER_VALIDATE_FLOAT
FILTER_VALIDATE_INT
FILTER_VALIDATE_IP
FILTER_VALIDATE_REGEXP
FILTER_VALIDATE_URL
FILTER_VALIDATE_EMAIL
FILTER_VALIDATE_ENCODED
FILTER_VALIDATE_NUMBER_FLOAT
FILTER_VALIDATE_NUMBER_INT
FILTER_VALIDATE_SPECIAL_CHARS
FILTER_VALIDATE_STRING
FILTER_VALIDATE_URL
session、cookie
$ _SESSION for storing session, corresponding to intermediate a, u like a disk, like a plate, must be turned session_start () function using $ _SESSION.
$ COOKIE [] role:
- Record certain information visitors.
- Pass variables between pages
The viewing Internet pages are stored in a temporary folder Cookie, you can improve the speed of browsing later.
function
- The return value of the function call when only returns a value, not echo to the screen, you can use the call to a variable, the variable echo output.
- Function names can use alphanumeric characters, but the number can not serve as the beginning. When called, the function names are not case sensitive. Function call in alphabetical order, you can customize the function before the function can be later customize. We can not function the same name. If you read the body of the function return, function behind the content will not be executed.
Argument is an incoming call when the actual parameter values. Parameter is a function of the parameters passed in the form. When the function is called, the arguments passed parameter. Parameter equal to the number may be greater than the real parameter. Func_get_args function () arguments may be passed acquired content within the function, and returns an array.
Object-Oriented
Relationship classes and objects:
Object: The object is instantiated from a class of
classes: abstract class is summed up by an object from the
class when an object is instantiated, new class () here can be added from time to increase parentheses.
Writing class, you can first write method, when writing methods, see the bridges needed, add a variable.set () and get ()
<?php
/**- By set, get private variable method by a common method to show out
* /
class People
{
Private $ name;
public function the setName ($ name) {
$ this-> name = $ name;
}
public function getName () {
return $ this- > name;
}
}
$ = new new people people;
$ people-> the setName ( 'flower');
$ people1 = $ people-> getName ();
echo $ people1;
?>
/ ** __construct not bother to call the above, automatically, concise code
* /
class Car
{the __construct function ($ CAR)
{
echo $ CAR;
}
}
new new Car ( 'bei Chi');
// php garbage collection mechanism, without using __destruct automatically recovered without variable
// called by the subdivision about php in, $ this-> method, if the subclass does not detect the parent, if the parent class is completely call parent :: method is used.
- By set, get private variable method by a common method to show out