Recently wrote quite a lot of PHP, but also contact with a lot of often used functions, most of them took notes, send a blog out. Learn together. In fact, the sense of learning a language, grammatical logic is soft literacy. The familiarity with the language can only grow with the use of time, when the function of a language, library, characteristics are deeply understood, talent is barely known as proficiency or mastery of it.
1. Trim (). Removes whitespace characters and other pre-defined characters from both ends of a string. You can certainly delete the specified characters.
Similarly, there are LTrim (), RTrim ().
2. __class__, the constant returns the name of the class when it is defined.
3. Strtotime (), which describes the date-time description of any English text as a Unix timestamp, for example strtotime (' Yesterday ') returns yesterday's Unix timestamp.
Often combined with date (). The function uses, for example, date (' y-m-d h:i:s ', Strtotime (' Yesterday ')) to return to the day of yesterday's month and seconds.
4. Intval (), converts any type of variable outside the array or class to an integer type.
Similar to have floatval () and so on.
5. Explode (), splits the string into an array by the specified character. Very practical!!
6. File_get_contents (), reads the entire file into a string.
The corresponding file_put_contents () can put a string into a file and can be placed directly into a text file. You can also export to a CSV file by using a comma-cut, and you can open it in Excel.
7. Php_eol, which represents a newline character. For example, combine trim () to use. Very practical. PHP has very many similar constants that represent the corresponding symbols.
8. Round (), the ability to retain the number of digits after the decimal point according to the specified number of digits, rounded save.
corresponding to the ceil () upward rounding, floor () down rounding, of course, you can also use the said Intval () directly take an integer ~.
9. Str_replace (). A very useful function to replace the specified character with the specified character from the specified string.
Int_set (), capable of passing two string variable arguments, so that one of the variables retains the specified value when the script executes and restores the original value at the end of the script.
System (), run an external program, and return the results. For example, run a shell command.
Opendir (), open a folder handle. The ability to add @ before the function to hide the output of the error.
There are also a number of corresponding file manipulation functions, such as chdir () changing the current folder to the specified folder. File_exists () infers whether the file exists, and unlink () is used to delete the specified file.
Array_shift () to delete the first element in the array. and returns the value of the deleted element.
There are also a number of corresponding array manipulation functions, such as array_flip () flipping an array of key and Value,array_merge () to merge two or more arrays into an array, Array_diff_key () Returns an array that contains all the key values in the array that are not in any of the other arrays. Array_unique () returns an array (which can be used to remove repeated elements) after repeating values in the divisor group. Is_array () infers if the variable is an array (because PHP is a weakly typed language and is therefore very useful), array_slice () removes a value in the array by condition. Array_values () returns an array of all key values in a given array without preserving the key name.
Count (). Very intuitive to return the number of elements in an array.
Unset (), releases the specified variable, for example, clears the value of the specified array.
Strpos () returns the position of the first occurrence of a string in a string.
Number_format (). The first parameter is a decimal number. The second parameter is a decimal number, and the third parameter is a symbol that cuts the decimals. The fourth parameter is a symbol for each thousand cut.
Implode (), merges the array into a string, corresponding to explode (), according to the specified cut character.
File (). Reads the entire file into an array. Each cell in the array is a corresponding line in the file.
Readdir (). Returns an entry in a folder handle that has Opendir () open.
Var_dump (). Prints information about the variable.
Similar to Print_r (), but the Var_dump () function is more specific.
Constant (), returns the value of the constant.
Feof (). The test has reached the end of the file.
Fgets () to read a row from the file pointer.
STRCASECMP (). A comparison of two strings.
. chr (), returns the character from the specified ASCII code.
Stripslashes (). Removes a backslash from a string.
Ucwords (). Capitalize the first letter of each word in a string.
Method_exists () to check if the method of the class exists.
Get_class (). Returns the class name of the object.
Extract (), import the variable from the array into the current symbol table, and the key name for the variable name. The key value is used for the variable value.
Require (), include (), are able to implement a reference to the specified PHP script file, the difference is the way the error is handled differently. The include () generates a warning that continues to run, while require () causes a fatal error to end the script.
33. Frequent use of MySQL operation functions
Mysql_connect (), mysql_select_db (), Mysql_close (), mysql_query (), mysql_num_rows (), mysql_num_rows (), Mysql_free_ Result (), mysql_error ()
Mysql_num_fields () returns the number of fields in the result set
Mysql_field_table () returns the name of the table that contains the specified field
Mysql_field_name () Gets the field name of the specified field in the result
Mysql_fetch_row () returns a row from the result set as a numeric array
PHP Feast--Frequent use of function highlights