PHP Most full note (a) (worth to collect, check it through)

Source: Internet
Author: User
Tags constant definition parse string sapi

PHP notes Come ~ Absolutely dry!

The following is my previous study of PHP notes, and occasionally will add some basic knowledge points in, and sometimes turned out to check.

Syntax error (syntax error) in the parsing phase, the source code is not executed, so there is no output. /* "Naming rules" */Constant Name Class constants recommended all caps, between words separated by underscores//Min_width
Variable names are suggested to be separated by underscores//$var _name
The name of the function is suggested using the Hump name method//VarName
Delimiter recommended ALL CAPS//<<<ding, <<< ' DING '
File name recommended full lowercase and underscore, number//func_name.php
Private property name, method name suggestion underline//private $_name _func
Interface name suggested add I_//interface i_name/* language Structure */array (), Echo (), Empty (), eval (), exit (), Isset (), list (), print ( ), unset () echo, print to omit parentheses. /* Predefined constant */path_separator//path delimiter (Windows is semicolon, Unix-like colon)
Directory_separator//Directory separator Php_eol//current system line break php_version//php version number Php_os//php Service operating system
PHP_SAPI//used to determine whether to use the command line or browser, if the php_sapi== ' CLI ' indicates that the Php_int_max INT maximum is executed at the command line, the 32-bit platform value is 2147483647
Php_int_size INT Word length, 32-bit platform value is 4 (4 bytes)
M_PI//PI value
M_e//Natural number
PHP Runtime Environment detection function php_sapi_name ()//returns a lowercase string of PHP and Web server interface type the function return value is consistent with constant PHP_SAPI!
Interface type: SAPI (the Server API, SAPI)
Possible values: Aolserver, Apache, Apache2filter, Apache2handler, Caudium, CGI, cgi-fcgi, CLI, continuity, embed, ISAPI, Litespeed Milter, Nsapi, phttpd, Pi3web, Roxen, thttpd, Tux, webjames/* case issues */
-Class name, method name, property name, function name: case insensitive
-variable name, constant name, element subscript: Case sensitive//variable identifier */variable variable $i = 3; $k = ' I '; echo $ $k; Output 3
Variadic function func () {echo ' hello! ';} $i = ' func '; $i (); Output Hello
Variable subscript $i = ' 1234 '; $k = 3;   echo $i [$k]; Output 4
Variable class name class Cls{public $k = ' Hello ';} $i = ' CLS '; $j = new $i; Echo $j->k;
Variable attribute class cls{public $k = ' Hello ';} $i = ' k '; $j = new CLS; echo $j $i;
Variable method class Cls{public function K () {echo ' Hello ';}} $i = ' k '; $j =new CLS; $j-$i ();/* variable variable */
* Used for business logic to judge to get some specific information $var _name = "Class_name";
$ $var _name = "PHP0913";        $class _name = "PHP0913"; $class _name is stored in memory var_dump ($class _name); Var_dump ($ $var _name);/* variable function */get_defined_vars//Returns an array of all defined variables (including environment variables, server variables, and user-defined variables)/* unset () */
* unset () deletes only the current variable name and reference, and its value is not deleted
* Reference passing, delete a variable and its reference, other variables and references exist, and the value still exists echo "<br/>";    $v 3 = ' value ';    $v 4 = & $v 3;    Unset ($v 4); Var_dump ($v 3, $v 4);/* The maximum lifetime of the variable */
* The execution period of the current script, the execution of the script ends, the variable disappears/* predefined variable/SUPER global variable */$GLOBALS $_cookie$_env$_files$_get$_post$_request$_server$_session/* constant Definition *  /define (constant name, constant value, [case-sensitive parameter])//true means that the/false is not distinguished by the case-sensitive const constant NAME = constant value//new, the recommended constant name can use special characters constant ($name)// Get constant Name
Example: Echo constant ('-_-');/* Constant correlation function */definedget_defined_constants/* predefined constants */
Absolute path to the file where the __file__ is located
The current line number in the __line__ file
directory where the __dir__ files are located
__function__ function name
Name of the __class__ class
Method name of the __method__ class
__NAMESPACE__ the name of the current namespace
/* Integral type */
The integer occupies 4 bytes, the total 4*8=32 bit, the maximum value is 2147483647, the minimum value is 2147483648, the absolute value of the minimum value is greater than the maximum value of 1
The highest is positive or negative, 1 is negative, and 0 indicates positive
/* Binary conversion function */
Only decimal and other binary conversions, only six kinds
When converting, the argument should be a string (that is, "0" or hexadecimal "0x", which is not included in octal)
Ten Dec
2 bin
8 Oct
Hex
Hexdec () hexadecimal to decimal can also be written hex2dec ()
Dechex () Decimal to hexadecimal can also be written dec2hex ()
Bindec () binary turn decimal can also be written bin2dec ()
Decbin () decimal turn binary can also be written dex2bin ()
Octdec () octal to Decimal can also be written oct2dec ()
DECOCT () Decimal turn octal can also be written dec2oct ()
/* Floating-point number */
Floating point number cannot compare size!!!
Almost all decimals, when saved, are approximate values rather than exact values!
Maximum value: +/-1.8E308
Maximum number of decimal digits that PHP can hold: 14 bits
/* Single-quote String */
Only backslashes and single quotes can be escaped in a single quote string
/* Double Quote String */
Parse string only once!!!
Eval executes the string as PHP code
Curly braces wrap variables, which determine the bounds of the variable name. such as: "Aaa{$bbb}CCC"
ASCII code can be converted to characters in double quotes
"\x61"-A//string does not need 0, the integer is the 0x preamble
"\x49\x54\x43\x41\x53\x54", Itcast
Convert ASCII to character function Chr ()
Convert character to ASCII function Ord ()
#双引号转义列表
\ nthe line break
\ r Enter
\ t Horizontal tab
\ \ Backslash
\$ Dollar Mark
\v Vertical Tab
\e Escape
\f Page Change
\ "Double quotation mark"
\[0-7]{1,3} matches the regular expression sequence with a character that is expressed in eight binary ways
\x[0-9a-fa-f]{1,2} matches the regular expression sequence with a character that is expressed in 16 binary ways
/* Delimiter */
Herodoc-function with double quotes, can parse
$str = <<<aaa
String content
AAA;
Nowdoc-function with single quote, cannot parse
Single quote only at start position
$str = <<< ' AAA '
String content
AAA;
/* Use of String */
A string can be used as a collection of characters, and each character can be accessed independently. Applies only to single-byte characters (letters, numbers, half-width punctuation marks), such as Chinese, are not available
$str = "ABCD";
Echo $str [3]; D
echo $str {0}; A
/* "Type operation function" */
Get/set Type
GetType ($var)//Get the data type of the variable
Settype ($var, $type)//Set the data type of the variable
Type judgment
Is_int
Is_float
Is_null
Is_string
Is_resource
Is_array
Is_bool
Is_object
Is_numeric detect if a variable is a numeric or numeric string
Convert to the specified data type
Boolval
Floatval
Intval
Strval
Cast type
(int)
(float)
(string)
(BOOL)
(array)
(object)
(unset)//convert to NULL
(binary) conversion and B-prefix conversion//conversion to Binary
Var_dump information about the print variable.
Displays structure information about one or more expressions, including the type and value of the expression.
The array recursively expands the value and displays its structure by indentation.
Var_export ($var [, BOOL $return])//output or return a string representation of a variable
$return: True to return the result of the variable after execution
Print_r to print easy-to-understand information about variables
Empty checks if a variable is null
Isset detecting whether a variable exists
/* "Process Control" */
Alternative syntax for an IF statement
if (condition judgment):
statement block;
ElseIf (conditional judgment):
statement block;
else:
statement block;
endif
Alternative syntax for Process Control
Commonly used when embedding HTML
Replace {with:, change} to endif; such as
endif
Endwhile
ENDfor
Endforeach
Endswitch
/* "Switch" */
Switch (condition) {
Case Status value 1:
statement block;
[Break;]
Case Status Value 2:
statement block;
[Break;]
Case Status Value 3:
Case Status Value 4:
statement block;
[Break;]
Default
statement block;
[Break;]
}
Switch is a state branch, a special loop
Calculate the state value first and then compare it to the judgment number.
Break Exit process
/* "For loop" */
for (conditional initialization expression; conditional judgment expression; conditional change expression) {
Loop body
}
Assuming that the loop body has been executed n times, the
Conditional initialization expression is executed 1 times
Conditional-judgment expression is executed n+1 times
Conditional change expression is executed n times
Attention:
1. The loop variable can continue to be used after the for statement has ended, and the value is the first failed value
2. The loop variable can be used in the For loop body
3. Any conditional expression can be omitted, but semicolons cannot be omitted
A. When a conditional initialization expression is omitted, the loop variable is assigned a value of NULL, and when the condition is judged,
Type conversions are then compared. You can also initialize outside the For statement.
B. When the conditional judgment expression is omitted, it means that the loop is true and goes into the dead loop
C. When the conditional change expression is omitted, it can be done in the loop body
4. Each expression can consist of more than one statement, with each statement separated by commas
If the conditional judgment expression consists of multiple statements, it will be executed, but only the last statement will be used as the judging condition.
5. For only traversing a numeric index subscript array
Array length function: Count ()
6. The statements that can be initialized should be placed within the conditional initialization expression, which saves a lot of execution times

PHP Most full note (a) (worth to collect, check it through)

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.