PHP Common system Functions Daquan

Source: Internet
Author: User
Tags scalar

String functions

Strlen: Get string length, byte length

Substr_count the number of occurrences of a string

SUBSTR: String intercept, get string (intercept by byte)

Mb_strlen
Mb_substr

STRCHR: Similar to substr, intercept from a specified position until the last

STRRCHR (get file suffix name): As with STRCHR, just start looking for characters from the right

Strtolower: All characters are lowercase (for the English alphabet)

Strtoupper: All characters are capitalized

Strrev: String inversion (can only reverse English: only one byte in English storage), reverse by byte

Strpos: Find the position of the corresponding character (digital subscript) from the string, and start at the far left

Strrpos: As with Strpos, just start looking from the right side of the string

Trim: Removes characters from both sides of the function, which is the default space

The Str_split function splits a string into an array.

The Chunk_split () function splits a string into a series of smaller parts

Str_repeat ("Shanghai", 5); Repeat the string "Shanghai" 5 times

Str_replace (' \ \ ', '/', dirname (DIR))); Replace

Ucfirst First Letter Capital

Time-Date function

Time: Gets the timestamp of the current time (int: Starting from GMT January 1, 1970 0:0 0 seconds) Number of seconds

Date: Time-serialization function that converts the specified timestamp to the display format of a given time date (random string: A professional format specifier), and if no timestamp is specified, the system uses the timestamp of the current time by default

Strtotime: The time-date format string is converted to the corresponding timestamp (as long as the correct English time expression can be converted)

Microtime: microsecond timestamp, returns different results according to different requirements mixed Microtime (Boolean type), can return a floating-point number of time, can also return an array (timestamp and number of microseconds)

Math-related functions

ABS: Absolute Value

Floor: down to floor (3.2) result equals 3

Ceil: Rounding up

Round: Rounding

Rand: Gets a random integer within the specified range

Mt_rand: Gets a random integer within a specified range (more efficient)

Min:php will treat a non-numeric string as 0, but if this is the smallest value, it will still return a string. If more than one parameter evaluates to 0 and is the Minimum, min () returns the string with the lowest alphabetical order, or 0 if there are no strings in it;

Max:php will treat a non-numeric string as 0, but if this is the maximum value it will still return a string. If more than one parameter evaluates to 0 and is the maximum, max () returns 0 of the value, and if there is no value of 0 in the argument, the string that is the largest in alphabetical order is returned. For multiple arrays, Max compares left to right, and returns the array as the maximum value if both array and non-array parameters are present.

Array-related functions

COUNT ()//non-array return 1

Key: Gets the subscript of the element to which the current pointer is pointing

Current: Gets the value of the currently pointing pointer to the element

Next: Gets the value of the next element and moves the pointer down

Prev: Gets the value of the previous element and moves the pointer up

End : Moves the pointer to the last element of the array and returns the value of the final pointer position

Reset: Moves the pointer to the first element of the array, returning the value of the final pointer position

Array_keys: Gets all the key names of an array, returning an indexed array

Array_values: Gets all the values of an array, returning an indexed array

Explode: Explode, a string in accordance with a specified rule (usually a special character), the array is divided into multiple segments, each paragraph as an element of an array, return an indexed array

Split similar to explode explode ('. ', ' abc.txt ') equals split (' \. ', ' abc.txt ')

Implode: Glue all elements inside an array into a single string, according to a specified rule (special character)

Join () combines array elements into a single string

Array_merge: Merge, which refers to the accumulation of elements in two arrays. If the following array has the same subscript (Key Name: Association) as the previous array, then the values of the subsequent elements will be overwritten, and if the index is the same subscript, the subscript will be automatically modified to overlay the preceding array.

array_reverse-returns the inverted array

Array_flip-exchanging keys and values in an array

Data structure Simulation function

Array_shift : POPs the element from the front of the array to get the value of the element

Array_pop: POPs the element from the back of the array to get the value of the element

Array_unshift: Pressing elements from the front of the array to get the number of elements in the current array

Array_push: Pressing elements from the back of an array to get the number of elements in the current array

Judging variables

Is_bool: Judging whether it is a Boolean type

Is_float: Judging floating-point type

Is_integer: Judging the integral type

Is_object: Judging objects

Is_array: Judging arrays

Is_string: Judging string

Is_resource: Judging Resources

Is_scalar:scalar is scalar and judgment is the basic data type: Integer, Float, Boolean and string

Is_null detects if the variable is null is returned true otherwise returns false. 1. Assigned value is NULL;2. The variable is not assigned; 3. be unset ()

Is_numeric: A string that determines a number or a pure number

GetType: Getting Data types

Settype: Changing the data type

Isset

Unset () If a global variable is unset () in the function, only the local variable is destroyed, and the variable in the calling environment keeps the same value as before the call to Unset (), if unset () A variable passed by reference in the function, Only the local variable is destroyed, and the variable in the calling environment keeps the same value as before the call to Unset ().
Empty//array (), "", 0, "0", Null,false all return True

File manipulation functions

Opendir ( path ): Opens a path resource (reads all the data inside the path into memory)

Readdir ( path Resource ): Reads the name of the file pointed to by the current resource pointer from the folder resource, and the pointer moves down one

Closedir ( resource ): Release the corresponding file resource

Scandir ( path ): reads all the file names inside a path, returns an array, and each element of the array is a file name.

File_exists: Determine if a file exists (file is generalized: path and file)

Is_dir: Determines whether a specified path exists (folder)

Is_file: Determines whether a specified path is a file (file)

mkdir: Create a path that will cause an error if the path exists

RmDir: removing folders

File_get_contents: Reads the contents of the data from within a specified file.

File_put_contents: Writes the specified string to the corresponding file

fopen: Opening a file resource

Fgetc:C for character, read one character at a time

Fgets:s represents a string, which means that multiple characters can be read, depending on the specified read length, or whether a newline is encountered (up to one row of data)

All two functions operate on the current resource pointer and move the pointer down after reading

Fread: Gets data of the specified length until the end of the file

Fwrite: Writes data to the location where the file resource pointer is located, writing does not move things that are already in the current position, but overwrites

Fseek: Assigning pointers to the corresponding positions

Fclose: Using the corresponding file resource

Copy: Copying

Unlink: Deleting files

Rename: Renaming files

Filemtime:m stands for Modify, the time when the file was last modified

FileSize: File size (bytes)

Fileperms: File permissions ( octal under Linux)

Sort

The Rsort () function is used to sort the array cells from high to low.
The Asort () function is used to sort the array cells from low to high and keep the index relationship.
The Arsort () function is used to sort the array cells from high to low and keep the index relationship.
The Ksort () function is used to sort the array cells from low to high by their key names.
The Krsort () function is used to sort the array cells by their key names from high to low.

Error

Error_reporting (E_all)

Ini_set (' display_errors ', 1)

Constant

Define () Defining constants
Defined () Detect if constants are defined

Serialization of

Serialize

Unserialize

Json_encode JSON Encoding of variables

Json_decode encoding a JSON-formatted string

Coding

Base64_encode This function encodes a string in MIME BASE64. The BASE64 encoded string contains only the English letter case, Arabic numerals, plus and backslash, a total of 64 basic characters, does not contain other special characters, so it is named BASE64.

Base64_decode decoding

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.