Learning plan and steps:
1. Learn to build development environment and operating environment
2. Learn basic syntax and use of functions: basic data types, array operations
3. Learn basic function implementation: database reading, adding, deleting, modifying, File operation; long connection, socket service, operation memcached
4, learn mainstream frameworks and systems
Output:
echo(), print()//Output value
var_dump() print_r()//Mainly used to output arrays
printf ("%s was founded on %s.", $founded, $state[$founded]);
print_r();
var_dump();//View the output value and type
Variable names are case-sensitive and method names are case-sensitive Regardless, the variable name and method name can be the same
Pay attention to the difference between single quotes and double quotes
Define variables: start with the $ symbol, static variables plus the type specifier static, and define strings without quotes
Define constants: define( AA, "12345"), to determine whether a constant is defined, use defined();
unset() is used to clear the object. The effect is the same as using NULL assignment. The object cleared by unset() is no longer isset().
isset() is used to determine whether the variable is set. Note the difference from empty(). empty() returns true for an object with a value of 0, while isset returns empty
gettype() gets the variable type
Parameter passing defaults to value reference. If you want to support object reference, add the ampersand symbol to the parameter
After defining the global variable, It can be read through ¥GLOBALS["name"]
require() require_once() functions to introduce external files and does not support return values. An error will terminate the following execution;
include() include_once() functions to introduce external files and supports return value, the error will not terminate subsequent execution.
Mathematical functions: round() ceil() rounding;
decbin(num) binary conversion
dechex(num) hexadecimal conversion
decoct(num) octal conversion
PHP’s data type conversion is a mandatory conversion, and conversion is allowed PHP data types are:
? (int), (integer): converted to integer
? (float), (double), (real): converted to floating point type
? (string): converted to string
? ( bool), (boolean): Convert to Boolean type
? (array): Convert to array
? (object): Convert to object
There are three conversion methods for PHP data types:
? Add parentheses before the variable to be converted Example of enclosed target type: $num2=(int)$num1;
?Use three specific type conversion functions, intval(), floatval(), strval() Example: $int=intval($str);
?Use the general type conversion function settype(mixed var,string type). For example: $flg=settype($num4,"int");
String:
Use the . sign to connect strings
to remove the spaces at both ends and the left and right spaces trim( ),ltrim(),rtrim();
String case conversion: strtolower(), strtoupper(), capitalize the first letter and change the rest to lowercase ucfirst(), capitalize the first letter of a word ucwords(),
Use to judge whether strings are equal == sign, you can also use the function:
Case-sensitive strcmp(a,b) returns 1 if the former is less than the latter, -1 if greater than the latter, 0 if equal,
is not case-sensitive strcasecmp(a,b) the former If it is less than the latter, it returns 1, if it is greater than the latter, it returns -1, and if it is equal, it returns 0.
Local comparison strncmp(a, b, len) intercepts the first len-length string starting from the first digit to participate in the comparison,
It is not case-sensitive and local comparison strncasecmp( a, b, len) intercept the first character starting from the len length string to participate in the comparison
Search string: find and return the string from the first occurrence to the end strstr(), find and return the last character from the last occurrence to the end String strrchr(), if not found, returns empty
Count the number of string occurrences: substr_count(str, "f"); You can set the starting point and length of the search substr_count(str, "f",2,2)
Find a single character in The last position in the string: strrpos(str, "f",2), if not found, returns false
Find the first position of the character/string in the string: strpos(str, "f",2) , return false if not found
Replace string: str_replace("a","b",str); The replaced can also be an array str_replace(["a","b"],"b",str); You can also search and replace from the specified position str_replace("a","b",str,30)
Split the string into an array: explode("ss",str);
md5 encryption: $newstr = MD5($abc) ;
Formatted output string: $newstr = sprintf("%01.3f", $money);
Regular execution: ereg("[0-9a-zA-Z]+",$name)
Array:
1 , array does not distinguish between the concepts of ordinary arrays and Object. They are all represented by arrays, which are divided into numerical index arrays and associative arrays. Pay attention to the type when using them. 2. PHP is a weakly typed language, which means you do not need to explicitly declare one. Arrays and their sizes. Instead, you declare and fill an array at the same time.
$capitals = array(
'Alabama' => 'Montgomery',
'Arizona' => 'Phoenix'
);
Additional array elements appended: $capitals['Arkansas'] = 'Little Rock';
Methods to add and delete data in the array: array_push(), array_unshift(); you can also directly add content to the array using $array[]="xxx"
Merge arrays: $capitals = array_merge($array1, $ array2);
Execute the specified method for each item in the array: array_map("fun_name", $array);
Array sorting: sorting by key: ksort();krsort();uksort(); sorting by value: asort ();arsort();uasort(); Disrupt the order of the array: shuffle(); Randomly select an item from the array: array_rand();
Determine whether a key in the array exists: array_key_exists(); Determine whether a certain key in the array exists Whether the value exists: in_array();
Search the array: array_search() If found, return the index/key, if not found, return false
Get the array key: array_keys(); Get the array value: array_values();
Exchange Key and value: array_flip() (I want to ask where this requirement is)
Judge whether it is an array: is_array();
foreach(); each(); list(); for(); key(); current(); count();
Date
getdate
date()
mktime()
Form
$_POST["data"] receives the data posted by the form like this
Connect to the database
$conn=mysql_connect($host, $user, $password ; Operation
Error
api Chinese manual: http://php.net/manual/zh/index.php
The above introduces the PHP learning notes - the main grammar and content, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.