php--most commonly used--must-have function summary! PHP Learner Collection Required!

Source: Internet
Author: User
Tags explode fread pow rtrim shuffle unique id uppercase letter

First, PHP system functions
Function Function Usage
Var_dump () Print variable structure information, including type and value. Array will recursively expand values Var_dump$arg1...);
Echo (): A grammatical structure Output one or more strings, without (), enclosed in single or double quotes. Variable direct OUTPUT, echo $arg 1, $arg 2 ...;
Isset () Returns ture if the variable is set and the value is not NULL, and vice versa Isset ($args)
Empty () Detects if the variable is empty Empty ($args)
Exit () Output a message and exit the current version Exit (' exit successful ')
Die () Output a message and stop code execution down Die (' Code stopped ')
Iconv () Character set converted by specified encoding Iconv (Incharset,outcharset, $STR)
Uniqid () Gets a unique ID (no parameter) or gets a unique ID with a prefix based on the current time microseconds (see parameters). Uniqid ([prefix name],[true])
GetType () Get data type GetType ($args)
Settype () Set the variable $arg to a data type Settype ($args, "[int][string] ...")
Serialize () Serialize $arg, i.e. convert to text to save or transfer without losing its type and structure Serialize (mixed $arg)
Unserialize () Deserializes the $STR to return the type and format information before serialization Unserialize ($STR)
GETCWD () Gets the directory where the script is currently running GETCWD ()
BaseName () Returns the Chinese part of the path BaseName ($url)
Preg_match () Use $string to match the regular expression, match the result with $res return match 1 or mismatch 0 Preg_match ($string, regular expression, $res)
Binary conversion function
Function Function Usage
Decbin () Decimal---binary Decbin ($num)
DECOCT () Decimal-to-octal Decoct ($num)
Dechex () decimal--Hexadecimal Dechex ($num)
Bindec () Binary---decimal Bindec ($num)
Octdec () Octal to Decimal Octdec ($num)
Hexdec () hexadecimal--and decimal Hexdec ($num)
Base_convert () Arbitrary binary conversions

Base_convert (value of the conversion,

The value of the binary, to be converted into the system)

English for each system:

Binary: Binary decimal: Decimal

Octal: octect 16 binary: Hexadecimal

Three, constant function
Function Function Usage
Define () Defines a constant, and the third parameter chooses whether to be case sensitive. Define (constant name, constant value, "true")
Defined () Determine if a constant exists Define (constant name)
Get_defined_constants () Get pre-defined constants Get_defined_constant ()
Iv. Function of Judgment
Function Function Usage
Is_bool () Determines whether a Boolean type Is_bool ()
Is_int () Determine if it is an orthopedic Is_int ()
Is_string () Determines whether a string Is_string ()
Is_float () Determines whether a floating-point type Is_float ()
Is_numeric () Determines whether a numeric or numeric string Is_numeric ()
Is_null () Determines whether the empty Is_null ()
Is_array () Determines whether an array Is_array ()
Is_dir () Determine if the path is Id_dir ()
Five, String function
Function Function Usage
Strstr () is an alias for STRCHR ()

Returns the string from the beginning of the $str needle first occurrence of the string to the end.

and case-sensitive, do not want to be case-sensitive:stristr ()

strstr ($str , $needle )
Strpos () Gets the position (subscript) of the first occurrence of $needle in $str, without returning false Strpos ($str, $needle)
Strrpos () Gets the position (subscript) of the last occurrence of $needle in $str, without returning false Strrpos ($str, $needle)
SUBSTR () Intercept string $str from $start position to $length string substr ($str, $start, $length)
Implode () To concatenate arrays into strings. Implode (', ', $arr)
Explode () To divide the string into groups Explode (', ', $str)
Str_split () Divide the string $str into an array of 5 per unit length Str_split ($STR, 5)
Str_replace () Replace a in string $str with B Str_replace (A, B, $str)
Strtolower () String converted to lowercase Strtolower ($STR)
Strtoupper () Convert string to uppercase Strtoupper ($STR)
Ucfirst () Converts a string $str the first character to uppercase Ucfirst ($STR)
Unwords () Converts each word in a string to an uppercase letter $str Unwords ($STR)
Trim () Remove whitespace characters and other characters at both ends of a string Trim ($STR)
RTrim () Remove whitespace characters and other characters to the right of a string RTrim ($STR)
Strlen () Get string length Strlen ($STR)
Substr_count () Count the number of occurrences of a string $ A in the $STR string Substr_count ($STR, "$a")
Str_repeat () Repeat output $str, number of $num Str_repeat ($str, $num)
Strpad () Use 0 padding on the left side of the $str to make the length $length Strpad ($str, $length, "0", Str_pad_left)
Strrev () Flip String Order Strrev ($STR)
RAND () Take a random integer between m-n Rand (M,N)
Mt_rand () Take a random integer between M-n to get faster than Mt_rand () Mt_rand (M,n)
POW () Take M's n-th square Pow (m,n)
Number_format () Format a number in thousands separator mode Number_format ($n)
six, array functions
Function Role Usage
Unset () Destroys the specified variable Unset ($arr)/unset ($arr [n])
Array_values () Gets all the values in the array and re-establishes the numeric subscript Array_values ($arr)
Array_keys () Gets all the key values in the array Array_keys ($arr)
Is_array () Determines whether an array Is_array ($arr)
In_array () Determines whether an array $arr contains an element $str In_array ($str, $arr)
Count () Statistic array length/statistic multidimensional array length Count ($arr)/count ($arr, 1)
Range () Create an array of 1-9 Rang (1,9), range (A-Z)
Array_merge () Concatenate multiple arrays into an array Array_merge ($arr, $brr ...)
Array_rand () Randomly extracts n cells in the array, returns the key value, becomes the new array Array_rand ($arr, N)
Shuffle () Scrambled Array Order Shuffle ($arr)
each () Returns the key/value pair of the current element in the array and automatically moves the array pointer forward one step each ($arr)
List (): Language structure Assign the values in the array to some variables List ($a, $b, $c) = $arr
Array_unshift () Insert one or more cells at the beginning of an array Array_unshift ($arr, $v 1, $v 2 ...)
Array_push () Inserts one or more cells at the end of the array Array_push ($arr, $v 1, $v 2 ...)
Array_pop () The last element of the array is removed and returned Array_pop ($arr)
Array_key_exist () Determine if the key $k exists in the array Array_key_exist ($k, $arr)
Array_search () Searches the array for the given value $v, and returns the corresponding key name if successful Array_search ($v, $arr)
Array_flip () Swap the keys and values of an array Array_flip ($arr)
Array_count_values () Count the number of occurrences of all values in the array Array_count_values ($arr)
Array_unique () Move duplicate values in an array Array_unique ($arr)
Sort () Sort the array in ascending order of the size of the values Sort ($arr)
Asort () Arranges the array in ascending order of value and keeps the index relationship Asort ($arr)
Rsort () Arranges the array in descending order of the size of the values, rearranging the indexes Rsort ($arr)
Arsort Sorts the array in descending order of the size of the values, keeping the index Arsort ($arr)
Natsort () Natural sorting (in line with People's Daily habits) Natsort ($arr)
Ksort () Arranges arrays in descending order of key size, preserving the association of key names to data Ksort ($arr)
Krsort () Arranges arrays in descending order of key size, preserving the association of key names to data Krsort ($arr)
Array_sum () Sum all the values in an array Array_sum ($arr)
Key () Gets the position of the traversal pointer in the array (key) Key ($arr)
Current () Get the value of the position where the pointer is Current ($arr)
Next () Moves the pointer back one position in the array Next ($arr)
Prev () Move the pointer in the array forward one position Prev ($arr)
Reset () Resets the position of the pointer in the array (pointing to the first position) Reset ($arr)
End () Move the pointer in the array to the last position End ($arr)
Seven, Time function
Function Role Usage
Time () Gets the current time stamp Time ()
Mktime () Gets the timestamp for the specified time Mktime (hours, minutes, seconds, months, days, years)
Date () $tmp time to specified format output Date (' y-m-d h:i:s ', $tmp)
Strtotime () Resolves a datetime description of any English text to a Unix timestamp Strtotime ("Now")
Viii. database functions
Function Function Role
Mysql_connect () Link MySQL Database Mysql_connect ($host, $user, $pwd)
mysql_query () Send a MySQL statement mysql_query (SQL statement)
MYSQL_FETCH_ASSOC () Takes a row of data in the result set to form an associative array and returns, and continues to move the internal data pointer MYSQL_FETCH_ASSOC ($result)
Mysql_fetch_array () Takes a row of data in the result set to form an array and returns, and continues to move the internal data pointer Mysql_fetch_array ($result, parameters)
Mysql_fetch_row () Takes a row of data in the result set to form an indexed array and returns, and continues to move the internal data pointer Mysql_fetch_row ($result)
mysql_select_db () Select Database mysql_select_db (database name)
Mysql_num_rows () Gets the number of query result records Mysql_num_rows (query result)
Nine, file operation function
fopen () Open file or URL fopen ("filename", "mode")
Fwrite () Writing content in a file Fwrite ("filename", "content")
Fclose () Close a file or URL fclose ("filename")
File_put_contents () Write content in one step File_put_contents ("filename", "content")
File_get_contents () Read content in one step file_get_contents ("filename", "content")
Fread () Reads the contents of a specified length file Fread ("filename", number of bytes)
FileSize () Get file content Length (in bytes) FileSize ("filename")
Fgets () Read a row Fgets ($handle, length)
File () To read an entire file into an array File ("filename")
Copy () Copy the file, the new file is named "NewFile" Copy ("filename", "NewFile")
Unlink () deleting files Unlink ($filename)
Filectime () Get File creation time Filectime ($filename)
Fileatime () Get file last access time Fileatime ($filename)
Filemtime () Get File modification Time Filemtime ($filename)
Feof () Determines whether the pointer reaches the end of the file Feof ($filename)
Json_encode () Compiling data into JSON data Json_encode ($a)
Json_decode ()

Encode JSON data into PHP data variables

When the argument is true, returns an array

Json_decode ($j, [false]/true)
10. Directory Operation function
Function Function Usage
mkdir () Create a directory with 0777 recursively created mkdir ("/path/to/my/dir", 0777);
RmDir () Delete Directory RmDir ($DIR)
Opendir () Open Directory Handle Opendir ($dir)
Readdir () Read Directory Readdir ($dir)
Closedir () Close Directory Closedir ($dir)
Rewinddir () Resetting Directory Resources Rewinddir ($dir)
File_exists () Determine if a file/directory exists File_exists ($filename/$dir)
Rename () Renaming files/Directories Rename ($filename/$dir, $newname)
DirName () DirName ($path) Returns the directory portion of the path
BaseName () Returns the file name portion of the path BaseName ($path)
PathInfo () Get path information PathInfo ($path, [options])

11. Class Functions
Function Function Role
Class_exists () Determine if a class exists Class_exists ($classname)
Interface_exists () Determine if an interface exists Interface_exists ($name)
Method_exists () Determine if the method exists Method_exists ($name)
Property_exists () Determine if a property exists Property ($name)
Get_class () Get class Name Get_class ()
Get_parent_class () Get Parent class Name Get_parent_class ()
Get_class_methods () Getting methods in a class Get_class_methods ()
Get_class_vars () Returns an array that consists of the default properties of the class Get_class_vars ()
Get_declared_class () Gets the name of the class that is defined Get_declared_class ()
__tostring () Called when the object is treated as a string __tostring ()
__construct () Automatically called when the new object __construct ()
__destruct () Automatically called when objects are destroyed __destruct ()
__clone () Automatically called when cloning an object __clone ()
__invoke () Automatically called when an object is called as a function __invoke ()
__set () Automatically called when a value is assigned to an inaccessible member property __set ()
__get () Automatically called when reading the value of a non-readable member property __get ()
__isset () Automatically called when using Isset () or empty () for an inaccessible member property __isset ()
__unset () Auto-tune when using unset () for inaccessible member properties __unset ()
Class_alias () Create an alias for a class Class_alias (original class, category name)
Get_object_vars () Returns an associative array containing the defined properties and values that are available for object Get_object_vars ()
Is_a () Returns TRUE if the object belongs to the class or if the class is the parent class of this object Is_a ($obj, $classname)
Is_subclass_of () Returns TRUE if the object owning class is a subclass of class class_name, otherwise FALSE is returned. Is_subclass_of ($obj, $classname)

php--most commonly used--must-have function summary! PHP Learner Collection Required!

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.