PHP Common system Constants
__file__
The full path and file name of the file. If used in the included file, returns the file name that is included. Since PHP 4.0.2, always contains an absolute path (if the symbolic connection is the resolved absolute path), and the previous version sometimes contains a relative path.
__dir__
The directory where the file resides. If used in the included file, returns the directory where the included files are located. It is equivalent to DirName (__file__). Unless it is a root directory, the name in the directory does not include the trailing slash. (New in PHP 5.3.0)
__function__
The name of the function (PHP 4.3.0 new addition). From PHP 5 This constant returns the name (case-sensitive) when the function is defined. In PHP 4, this value is always in lowercase letters.
__class__
The name of the class (PHP 4.3.0 new addition). From PHP 5 This constant returns the name of the class when it is defined (case-sensitive). In PHP 4, this value is always in lowercase letters.
__method__
The method name of the class (PHP 5.0.0 new addition). Returns the name of the method when it is defined (case-sensitive).
Mathematical Operation function
ABS (x)
The function returns the absolute value of x.
Ceil (x)
Rounds up to an integer closest to X.
Floor (x)
Rounds down to an integer closest to X.
Mt_rand (min, max)
Randomly returns a number between Min and Max
Intval (x)
Convert data of type X to int
Floatval (x)
Convert x to float type data
String manipulation functions
Addcslashes-adds a backslash escape character for some characters inside a string
CHR (x)-Returns the ASCII code of a character
Echo-used to display some content
Explode-converts a string into an array form with a separator
htmlspecialchars-convert some characters in a string to HTML entities
implode-to convert an array to a string with a specific separator character
ltrim-to remove whitespace to the left of a string or to a specified character
rtrim-remove whitespace to the right of a string or a specified character
trim-remove whitespace or specified characters on either side of a string
md5-a string for MD5 algorithm encryption
nl2br-replacing the newline character "\ n" in a string with "<br/>"
str_replace-matching and replacing strings
strip_tags-remove HTML and PHP code from a string
Stripos-finds and returns the position of the first occurrence, matching is case-insensitive
stristr-returns a portion of a string by comparison, case-insensitive compared
Strlen-gets the encoded length of a string
strpos-Find and return the position of the first occurrence
strrchr-returns a part of a string by comparing it from backward to forward
Strripos-finds and returns the position of the first match from the back, matching is case insensitive
strrpos– Find and return the position of the first match from behind
strstr-returns a portion of a string by comparison
strtolower-converting a string to lowercase
strtoupper– converting a string to uppercase
substr-to intercept a string
Ucfirst-converts the first letter of a given string to uppercase
ucwords-the first letter of each English word of the given string into uppercase
Array Common operations
array-creating a new array
array_keys-returns all the key names in the array
Array_map-the callback function to the cell of the given array
array_merge-merging one or more arrays
array_pop-pops the last cell of the array (out of the stack)
array_push-pressing one or more cells into the end of the array (into the stack)
array_rand-random extraction of one or more cells from an array
Array_shift-moves the cell at the beginning of the array to a group
array_unshift-inserting one or more cells at the beginning of an array
array_slice-remove a paragraph from an array
array_splice-remove part of the array and replace it with other values
count-count the number of cells in an array or the number of properties in an object
each-returns the current key/value pair in the array and moves the array pointer forward one step
end-the inner pointer of an array to the last cell
in_array-checks if a value exists in the array
array_key_exists-checks whether the given key name or index exists in the array
next-moves the inner pointer in the array forward one
reset-the inner pointer of an array to the first cell
rsort-reverse sequence of an array
shuffle-Array is scrambled
sort-sorting an array of arrays
directory and file manipulation functions
I. Types of files
1.filetype ()
Get file type function, parameter is string (path + file name)
The return value is a string, file (normal), dir (directory), or unknown (unknown file)
2.is_file () Is_dir ()
Returns a Boolean value that determines whether the type is
Second, the file attributes (the following function parameters are file names)
1.file_exists () Check whether a file or directory exists
2.filesize () Get file size, error returned false
3.filectime () Get creation time
4.filemtime () Get modification time
5.fileatime () Get access time
6.stat () Get most of the file property values
Third, the analysis directory
1.basename (Path,[suffix]) returns the file name portion of the path, and the second parameter is an extension (such as "PHP" or ". php"), if given, the return value no longer has an extension
2.dirname (path) returns the name of the directory after removing the file name
3.pathinfo () returns an associative array, including dirname (directory name), basename (base name), extension (extension)
Iv. traversing the Directory
1.opendir () Opens the specified directory and returns a directory handle that can be used by other directory functions. Failed to return false
2.readdir () reads the specified directory, the parameter is a directory handle, returns a file name for the current directory pointer position, and moves the pointer back one. No more files returned false
3.closedir () closes the specified directory with the parameter directory handle
4.rewinddir () Rewind the directory handle, the parameter is a directory handle, reset the directory pointer to the beginning
V. Creating and Deleting Directories
1.mkdir () Create a new directory with the parameter directory name
2.rmdir () Delete the directory, only the empty directory is deleted, such as non-empty, you must first enter the directory, the files in which the unlink () function to delete
VI. Copy or move a directory
1. Replication: There are no specific functions in PHP, you must first create a new directory mkdir (), and then use the copy () function to copy each file.
2. Move: Copy First, then delete the original directory
Vii. opening and closing of files
1.fopen (Filename,mode[,use_include_path[,zcontext]]) Open the file, the parameter is the filename, the file mode, the third parameter optional, set to 1 will allow PHP to consider configuring the path specified in directive include_path, The fourth parameter is optional, setting allows the file name to start with the protocol name, such as http://. Returns the file pointer, which fails to return false.
Model Summary:
R Read-only
r+ Reading and writing
W write only (file exists, delete old data, file does not exist, create this file)
w+ Reading and Writing (W)
X write (file exists, return false, file does not exist then create, local only)
x+ Read and write (same as X)
A write (pointer to end of file, created if file does not exist)
A + write (same a)
b binary Mode
T text mode
2.fclose () off
Viii. operation of the contents of the file
1.fwrite (Handle,string[,length]) writes a string. \n\r is the line end character. Returns the number of characters written, and the failure returns false.
2.fread (handle,length) Read Open file
3.file_get_contents () reads a file into a string
4.fgets (Handle[,length]) returns one row
5.fgetc () return character
6.file () reads a file into an array, one element for each behavior.
7.readfile () read a file, output to output buffer
8.feof () to determine if the end of the file is reached, yes returns true
9.file_get_contents ()
X. File locking mechanism (prevents multiple users from accessing the same file simultaneously resulting in file clutter)
1.flock (Handle,operation[,&wouldblock]) file locking operation, parameter two: Lock_sh shared lock, read data use; LOCK_EX exclusive lock, write data use; Lock_un release lock, LOCK_NB additional lock to prevent clogging when locked. Parameter three: set to 1 o'clock to block other processes during locking.
X. Copying and deleting files
1.copy (source file, destination file) copy
2.unlink (destination file) Delete file
Xi. File Upload and download
1. Global array $_files
$_files["MyFile" ["Name"] Original name, with extension
$_files["MyFile" ["size"] uploaded file size in bytes
$_files["MyFile" ["Tmp_name"] temporary file name after uploading
$_files["MyFile" ["Error"]
0: Success;
1: Size exceeds php config file limit;
2: Size exceeds the form limit;
3: File upload is incomplete;
4: No files uploaded
$_files["MyFile" ["type"] gets the MIME type of the uploaded file
2.is_uploaded_file () to determine if it was uploaded via HttpPost
3.move_uploaded_file () move uploaded files from a temporary location to a new location
Date and Time functions
Date
Usage: Date (format, [time]);
If there is no time parameter, the current time is used. The format is a string, replaced by the number of seconds since a start time (January 1, 1970)
Time ()
Usage: Time (); Returns the number of seconds since zero January 1, 1970.
Microtime ()
Usage: microtime (); Returns a string separated into two parts, followed by time ()
The first part of the return value is the number of microseconds.
Set_time_limit
Usage: set_time_limit (number of seconds);
Specifies that the program must run at the end of the specified number of seconds from the time the sentence is run, and the program exits with an error
Mktime (hours, minutes, seconds, months, days, years)
Returns the number of seconds in a given time
Strtotime (string format of time) returns the number of seconds in a given time
Regular-expression functions
Preg_match (String $pattern, String $content [, array $matches])
Searches the $content string for content that matches the regular expression given by the $pattern. If $matches is provided, the matching result is placed in it.
Preg_match_all (String $pattern, String $content [, array $matches])
Similar to the Preg_match () function. If a third parameter is used, all possible matching results are put in. This function returns the number of times the entire pattern matches (possibly 0) and returns False if an error occurs.
Preg_replace (mixed $pattern, mixed $replacement, mixed $subject [, int $limit])
Searches for the pattern string $pattern in $string and replaces the matched result with $replacement. When a pattern cell (or sub-mode) is included in a $pattern, the position of the $replacement in the form "\1" or "$" is replaced by the contents of those sub-patterns that are matched in turn. "+" or "$" means the contents of the entire matching string. It is important to note that the backslash is used as an escape character in double quotes, so you must use the form "\\0", "\\1". The first three parameters can be used arrays, the fourth parameter $limit can set the number of substitutions, the default is to replace all. The first three parameters can be used arrays, the fourth parameter $limit can set the number of substitutions, the default is to replace all.
Preg_split (String $pattern, string $string [, int $limit])
This function returns an array of strings, each of which is $string by a regular expression $pattern as a substring of the boundary. If $limit is set, the returned array contains a maximum of $limit cells.