This article is about the PHP basic function Summary, has a certain reference value, now share to everyone, the need for friends can refer to
String function Library
int strlen (string $str): Returns the length of the given string int strpos (string $str 1,string $str 2): Calculates the location of the first occurrence of $str2 in $str1 string strstr (String $ Str1,string $str 2): Returns the first $STR2 start to the last string in $str1 (contains $str2), the alias STRCHR () string stristr:strstr () function ignores the case of version int Strrpos ( String $str 1,string $str 2): Calculates the last occurrence of $str2 in $str1 string strrchr (String $str 1,string $str 2): Returns the last $ in $str1 STR2 begins to the last string (contains $str2) array explode (string $delimiter, String $str): Splits the $str in $delimiter as a split standard into multiple strings and returns a string as an array Implode (string $glue, array $arr): Connects each element in $arr with $glue string substr (string $str, int $start, [int $len]): Returns $STR in $ The start position starts at the length of the $len string, and if $len does not, returns all remaining String/array Str_replace (String/array $search, String/array $replace, string/ Array $subject [, int & $count]): The return value type depends on the $subject type, replacing $searchstring strtoupper (string $str) in $subject with $replace: the $ The letters in STR are converted to uppercase string Strtolower (String $str): Converts the letters in $str to lowercase string ucwords (string $str): capitalizes the first letter of a word in $str string Ucfirst ( String $str): Capitalize the first letter in $str string Strrev (String $str): Reverses the $STR string MD5 (string $str): Computes $str hash value for the MD5, which is the encrypted stringSHA1 (String $str): Computes the SHA1 hash value of $STR, which is the encrypted string strip_tags (String $str): Removes HTML and PHP tags from $str, useful string RTrim (string $str [, String $character _mask= ' \t\n\r\0\x0b '): Removes the white space character at the end of the $str and, through the second argument, can also specify that some characters are removed string trim (string $str [, String $character _mask]= ' \t\n\r\0\x0b '): Removes white space characters from the end of the $str, and can also be specified by the second parameter to delete certain characters
Date Time Function library
int time (): Returns the current UNIX timestamp (GMT 1970-01-01 00:00:00 to the current time in seconds) string date (string $format [, int $timestamp =time ()]): by $ Format format converts timestamps to string time, usually in $format= ' y-m-d h:i:s ' int strtotime (string $str [, int now=time ()]) : Converts the string time in any English format to a timestamp string/float microtime ([bool $get _as_float]): Returns the Unix timestamp and microseconds of the current time, without the $get_as_float parameter, returns string ' The time stamp portion of the microsecond part ', can be divided by the explode () function to calculate the time stamp part and the microsecond fraction; if there is a $get_as_float parameter and true, the float timestamp is returned. The number of microseconds is directly subtracted
Array function Library
int count (Array/object $var [, int $mode =count_normal]): Gets the length of the array or the number of properties of the object, if $mode is count_recursive or 1, You can recursively calculate the number of elements of a multidimensional array int/string array_search (mixed $needle, array $haystack [, BOOL $strict =false]): The return value type depends on the array of lookups. Whether the haystack is an indexed array or an associative array. If $strict is true, it will not only judge the value, but also the type, and for the object, it must be the same instance! BOOL Array_key_exits (int/string $needle, array $haystack): Determines if $needle is $haystack key array array_merge (array $arr 1,array $arr 2,...) : Appends $arr2 to $arr1 to form a new array. If $ARR2 has the same string key as in $arr1, the value of the key in $ARR2 overrides the string key in $arr1, and if $ARR2 has the same integer key in $arr1, the value in $ARR2 does not overwrite the key in $ARR1. Instead, continue to follow the integer key order (for example, $arr 1 has two integer keys 0, 1, $arr 2 also has two integer key 0, 1, then the merge, $arr 2 of the original two integer keys will be 2, 3; For example, there is no integer key in $arr 1, $ There are two integer keys in the arr2 1, 3, then the merge, $arr 2, the original two integer keys will become 0, 1) appended to the back int array_unshift (array & $arr, mixed $val 1[,mixed $val 2,...]) : Insert $valn 、...、 in $arr header $val 2, $val 1, and reorder integer key, string key unchanged, return $arr new length int array_push (array & $arr, mixed $val 1[,mixed $val 2 ,...]) : Inserts $val1, $val 2 、...、 $valn in $arr, and returns the new length of $arr. In fact, if you insert an element in the tail, you can directly $arr[]= the $valmixed array_pop (Array & $arr): $arr The last element pops up and returns the value of the element that pops up mixed array_pUsh (Array & $arr): POPs the $arr first element and returns the value of the element that pops up. And reorder integer keys, string key invariant array array_reverse (array $arr [, BOOL $preserve _keys=false]): Reverses $arr, default integer key reordering, string key unchanged, if $preserve_ Keys=true, the integer key and the string key are unchanged and return the array array_unique (array $arr [, Boo $sort _flags=sort_string]): Removes duplicate values from $arr. Key name retention problem, two duplicate values have a different key name, exactly keep that key name? Instead of simply keeping it in front, you sort all the values in the $arr by string and then take the key of the previous value! Once again, the values are first converted to string, sorted and compared, that is, the int 4 is the same value as String ' 4 '! void unset (mixed $val [, mixed $val ...]) : Releases the given variable, noting that unset can only release an array element, not an array mixed end (array & $arr): Moves the inner pointer of the array to the last element and returns the last element value bool Sort (Array & $arr [, $sort _flags=sort_regular]) : Sorts the array (low to High), returns true successfully, and fails returns false. After sorting the array with integer key sort bool Asort (array & $arr [, $sort _flags=sort_regular]): Sorts the array (low to High), returns true successfully, and fails returns false. Sorted after array key invariant bool Arsort (array & $arr [, $sort _flags=sort_regular]): Same as Asort, only high to low bool Ksort (array & $arr [, $sort _ Flags=sort_regular]): Sort by key (low to high), sort after array key invariant bool Ksort (array & $arr [, $sort _flags=sort_regular]): Sort by key (high to low), After sorting the array key is invariant to string serialize (mixed $val): Serializes $val, $val cannot be a resource type mixed unserialize (strinG $val): Deserialize the $val
Library of Mathematical functions
Int/float ABS (int/float $num): Returns the absolute value of the $num float round (float $num [, int $precision =0] [, int $mode]): Rounds the $num, retains the decimal point Precision bit float ceil (float $num): Take the whole float floor (float $num): int/float/string max (int/float/string $val 1,int/ Float/string $val 2[,...]) : Returns the maximum value. If there is only one argument and an array, the element with the largest element value in the array is returned. Min () find the minimum value float sqrt (float $num): $num square root, $num negative return nanint rand (int $min, int $max)/int rand (void): Returns a random integer between $min and $max/ Returns a random integer between 0 and Getrandmax () (on Win, 32767). The Mt_rand () function works better
MySQL extension function library [PHP5.5.0]
Resource mysql_connect ([string $server [, String $username [, String $password [, bool $new _link [, int $client _flags]]]) : Open a new connection or re-use the old connection resource mysql_query (string $sql [, Resource $link _identifier=null]): Send an SQL statement bool mysql_select_db ( String $db _name[,resource $link _identifier]): Select database bool Mysql_free_result (Resource $result): Release result set memory bool Mysql_close ( [Resource $link _identifier=null]) : Closes a non-persistent MySQL connection int mysql_affected_rows ([resource $link _identifier=null]): The number of records affected by the previous MySQL operation String Mysql_client_ Enconding ([Resource $link _identifier=null]): Returns the value of the Character_set variable in the MySQL server, which is the client character set bool Mysql_data_seek (resource $ Result,int $row _number): Moves the pointer in the result set string Mysql_error ([resource $link _identifier]): Returns an error message for a MySQL operation int Mysql_insert_ ID ([resource $link _identifier]): Gets the Idint mysql_num_rows (Resource $result) produced by the previous insert operation: Gets the number of records in the result set int mysql_num_ Field (Resource $result): Gets the number of fields in the result set array Mysql_fetch_array/row/assoc/object (Resource $result): Remove a row from the result set resource Mysql_pconnect (): Open MySQL persistent connection, mysql_close () cannot close the connection
PDO extension function library
PDO class object (PDO) __construct (String $dsn [, String $username [, String $password [, array $driver _options]]) : Create a PDO instance representing the connection request bool SetAttribute (int $attribute, mixed $value): Sets the database connection properties. For example, $attribute=pdo::attr_case indicates setting the result set subscript case, the corresponding value is $value=pdo::case_lower (lowercase), $value =pdo::case_upper (uppercase), $value = Pdo::case_natural (Natural) object (pdostatement) query (String $sql): Executes an SQL statement that returns a Pdostatement object, typically a SELECT statement that executes the INT exec ( String $statement): Executes an SQL statement and returns the number of rows affected, usually by executing an INSERT, delete, UPDATE statement, and the query () method to execute the SELECT statement! Object (pdostatement) prepare (string $statement [, array $driver _options=[]): Bulk Execute SQL statement (either INSERT, delete, UPDATE, Select), return a Pdostatement object, and then use its execute () method to execute $statement this preprocessed SQL statement (contains placeholders?). ) Pdostatement class bool Setfetchmode (int $mode): Sets the result set pattern, $mode values are PDO::FETCH_ASSOC (associative array), Pdo::fetch_num (indexed array), PDO:: Fetch_both (mixed array), Pdo::fetch_obj (anonymous object) mixed FETCH ([int $fetch _style]): Returns one of the records in the result set, $fethc similar to the $mode effect above mixed Fetchall ([int $fetch _style]): Returns an array of all records formed with the result set int rowCount (void): Returns the number of records affected by the previous SQL statement (INSERT, delete, update) int Execute ([array, $input _parameters]): Executes a preprocessing statement
Directory/File function library
Directory function Resource Opendir (string $path): Open $path directory, return a resource handle string Readdir (Resource $dir _handler): Return $dir_ Handler the filename of the next file, array scandir (string $path [, int $sorting _order]): Iterates through all subdirectories (not recursively) or files in $path, sorted alphabetically by default in ascending order $sorting _order =1 in descending bool Is_dir (string $filename): Determines whether the file name is a directory. Note that if $filename is a relative path, the relative current path is String dirname (string $path): Returns the directory portion of the $path (the last/and subsequent contents are removed). If there is no/(one file alone), it is returned. (represents the current directory). Win in/and \ Both, Linux can only be/represent path bool MkDir (string $path [, int $mode = 0777]): Create $path directory. For example, the date is the directory name, mkdir (date (' Ymd ')), bool File_exists (string $filename): Determines whether $filename exists, $filename can be a directory or file bool rename ( String $oldname, String $newname): Rename $oldname to $newnamebool rmdir (string $dirname): Delete $dirname. Note $dirname must be empty directory void Closedir ([resource $dir _handle]): Close Open Directory handle file function bool Is_file (string $filename): Judge $ FileName is a normal file resource fopen (string $filename, String $mode): Opens a local file or URL, $mode specifies the open mode. R Read-only mode, the file pointer to the file header, r+ read-write mode open, the file pointer to the file header, W write open, the file pointer to the file header, and the file size is truncated to 0, and if the file does not exist, try to create it; w+ read-write mode, the file pointer to the file header, and the If the file does not exist, it attempts to create it; a Write method opens, the file pointer points to the end of the file, and the file does not exist.A + read-write mode opens, the file pointer points to the end of the file, and the file does not exist to try to create it. Returns the file pointer resource int fwrite (resource $handle, String $content): $handle is the file pointer resource returned by fopen, $content is the content to write. Returns the number of characters written by bool Fclose (Resource $handle): Close $handlestring fread (resource $handle, int $length): characters that read $length bytes length stop. Fread two cases to stop reading, one is to read the $length byte length, and the second is to read the end of the file EOF. Returns the Read string fgets (Resource $handle): reads a row of $handle string Fgetss (Resource $handle): reads a row of $handle and filters out HTML and PHP tag int FileSize (String $filename): Gets the size of $filename int file_put_contents (string $filename, String/resource/array $content [, int $flags = 0]): equivalent to calling fopen (), fwrite (), fclose () method sequentially, $flags =file_append represents appending string file_get_contents (string $filename ): Equivalent to calling fopen (), Fread (), fclose () in turn
graphics image function library
Verification code principle: Generate random strings, stored in the session, and the use of graphic image library, it is depicted as an image of the output, the user to view the image to identify random strings, the input and the session of the random string comparison resource imagecreatetruecolor (int $ Width,int $height): Creates a wide $width, high $height black image. Returns the image resource $image. Note that you must follow the GD library, and the version is higher than 2.0int imagecolorallocate (resource $image, int $red _rgb,int $green _rgb,int $blue _rgb): to $ Image assigns colors that can be used, RGB color, $red _RGB represents the red component of the generated color (0-255 or 0x00-0xff), $green _rgb and $blue_rgb. Returns an integer identifier that represents a color bool Imagefilledrectangle (resource $image, int $x 1,int $y 1,int $x 2,int $y 2,int $color): Draw a rectangle on the $image and $color Fill, ($x 1, $y 1) represents the upper-left coordinate of the rectangle, ($x 2, $y 2) represents the lower-right coordinate of the rectangle, the upper-left corner of the $image is the coordinate origin bool Imageline (resource $image, int $x 1,int $y 1, int $x 2,int $y 2,int $color): Draw a $color-colored segment on the $image. $color are usually distributed randomly, i.e. imagecolorallocate (resource $image, rand (0,255), Rand (0,255), Rand (0,255)). BOOL Imagesetpixel (resource $image, int $x, int $y, int $color): Draw a $color-colored dot on the $image array imagettftext (Resource $image, Float $size, float $angle, int $x, int $y, int $color, string $fontfile, String $text): Writes UTF-8 encoded $text to $image. Returns a total of 8 elements that contain the text message written on the $image, bool Imagestring (Resource $iMage,int $font, int $x, int $y, string $text, int $color): Draw a line of strings horizontally, much simpler and weaker than Imagettftext () bool imagegif/imagepng/ Imagejpeg (Resource $image [, String $filename =null]): Outputs $image to the browser or write to the file (when $filename is specified). If the output is to the browser, it is usually preceded by the header (' Content-type:image/gif '), specified, and cannot be preceded by any character output. BOOL Imagedestroy (Resource $image): Destroy $image (Reclaim $image Resources) resource Imagecreatefromjpeg/png/gif (string $filename) : Image created by file or URL int imagesx (resource $image): Gets the width of the image int Imagesy (resource $image): Gets the height of the image bool Imagecopyresampled ( Resource $dst _image,resource $src _image,int $dst _x,int $dst _y,int $src _x,int $src _y,int $dst _w,int $dst _h,int src_w,int $SRC _h): Copy part of $src_image to $dst_image bool Imagecopyresized (Resource $dst _image,resource $src _image,int $dst _x,int $DST _y,int $src _x,int $src _y,int $dst _w,int $dst _h,int src_w,int $src _h): No imagecopyresampled () high quality