Home > Backend Development > PHP Tutorial > PHP common functions (2)

PHP common functions (2)

巴扎黑
Release: 2016-11-21 10:09:31
Original
1196 people have browsed it

In daily development, most novices are confused about how to remember so many PHP built-in functions. In fact, as long as you know that this thing exists, you will naturally remember it when you use it a lot. Here is a collection The most commonly used functions when developing PHP, I hope it will be helpful to you. The


acos() function returns the inverse cosine of a number.
abs() function returns the absolute value of a number.
mail() function allows you to send emails directly from your script.
The libxml_use_internal_errors() function disables standard libxml errors and enables user error handling.
The libxml_get_last_error() function gets the last error from the libxml error buffer.
The libxml_get_errors() function gets errors from the libxml error buffer.
libxml_clear_errors() function clears the libxml error buffer.
The setrawcookie() function does not URL encode the cookie value and sends an HTTP cookie.
The setcookie() function sends an HTTP cookie to the client.
headers_sent() function checks if/where HTTP headers are sent. The
headers_list() function returns a list of sent (or to be sent) response headers. The
header() function sends raw HTTP headers to the client.
ftp_systype() function returns the system type identifier of the remote FTP server.
ftp_ssl_connect() function opens a secure SSL-FTP connection.
ftp_size() function returns the size of the specified file.
ftp_site() function sends SITE command to the server.
ftp_set_option() function sets various FTP runtime options.
ftp_rmdir() function deletes a directory.
ftp_rename() function changes the file or directory name on the FTP server.
ftp_rawlist() function returns a detailed list of files in the specified directory.
The ftp_raw() function sends a raw command to the FTP server.
ftp_quit() function closes the FTP connection.
ftp_pwd() function returns the current directory name.
ftp_put() function uploads files to the server.
ftp_pasv() function sets passive mode on or off.
ftp_nlist() function returns the file list in the specified directory.
ftp_nb_put() function uploads files to the server (non-blocking).
ftp_nb_get() function gets files from FTP server and writes to local files (non-blocking).
The ftp_nb_fput() function uploads an open file and saves it as a file on the FTP server (non-blocking).
ftp_nb_fget() function downloads a file from the FTP server and saves it to a file that has been opened locally (non-blocking).
ftp_nb_continue() function continuously obtains/sends files.
ftp_mkdir() function creates a new directory on the FTP server.
ftp_mdtm() function returns the last modification time of the specified file.
ftp_login() function logs in to the FTP server.
ftp_get() function downloads a file from the FTP server.
The ftp_get_option() function returns various option settings for the current FTP connection.
ftp_fput() function uploads an open file to the FTP server.
The ftp_fget() function downloads a file from the FTP server and saves it to an open file locally.
The ftp_exec() function requests the execution of a program or command on the FTP server.
ftp_delete() function deletes a file on the FTP server.
ftp_connect() function establishes a new FTP connection.
ftp_close() function closes the FTP connection.
ftp_chmod() function sets the permissions of the specified file on the FTP server.
ftp_chdir() function changes the current directory on the FTP server.
ftp_cdup() function changes the current directory to the parent directory on the FTP server.
ftp_alloc() function allocates space for files to be uploaded to the FTP server.
filter_var() function filters variables through the specified filter.
filter_var_array() function obtains multiple variables and filters them.
filter_list() function returns an array containing all supported filters. The
filter_input_array() function obtains multiple inputs from outside the script and filters them. The
filter_input() function gets input from outside the script and filters it.
filter_id() function returns the ID number of the specified filter.
filter_has_var() function checks whether a variable of the specified input type exists.
unlink() function deletes files.
umask() function changes the current umask.
touch() function sets the access and modification time of the specified file. The
tmpfile() function creates a temporary file with a unique file name in read-write (w+) mode.
tempnam() function creates a temporary file with a unique file name.
symlink() function creates a symbolic link.
stat() function returns information about the file.
set_file_buffer() function sets the buffer size of the open file.
rmdir() function deletes empty directories.
rewind() function rewinds the position of the file pointer to the beginning of the file.
The rename() function renames a file or directory.
realpath() function returns the absolute path. The
readlink() function returns the target pointed to by the symbolic link.
readfile() function outputs a file.
popen() function opens the process file pointer.
pclose() function closes the pipe opened by popen(). The
pathinfo() function returns file path information in the form of an array.
parse_ini_file() function parses a configuration file and returns the settings in the form of an array.
move_uploaded_file() function moves the uploaded file to a new location.
mkdir() function creates a directory.
lstat() function returns information about a file or symbolic link.
linkinfo() function returns connection information.
link() function establishes a hard link.
is_writeable() function determines whether the specified file is writable.
is_writable() function determines whether the specified file is writable.
is_uploaded_file() function determines whether the specified file was uploaded through HTTP POST.
is_readable() function determines whether the specified file name is readable.
is_link() function determines whether the specified file name is a symbolic link.
is_file() function checks whether the specified file name is a normal file.
is_executable() function checks whether the specified file is executable.
is_dir() function checks whether the specified file is a directory.
glob() function returns the file name or directory matching the specified pattern.
fwrite() function writes to a file (safe for binary files).
ftruncate() function truncates the file to the specified length.
ftell() function’s current position in the open file.
fstat() function returns information about open files.
fseek() function locates in the open file. The
fscanf() function parses input from an open file according to the specified format.
fread() function reads files (safe for binary files).
fputs() function writes to files (safe for binary files).
fputcsv() function formats rows to CSV and writes to an open file.
fpassthru() function outputs all remaining data at the file pointer.
fopen() function opens a file or URL.
fnmatch() function matches a file name or string based on a specified pattern.
flock() function locks or releases a file.
filetype() function returns the type of the specified file or directory.
filesize() function returns the size of the specified file.
The fileperms() function returns the permissions of the file or directory.
fileowner() function returns the owner of the file. The
filemtime() function returns the last modification time of the file content. The
fileinode() function returns the inode number of the file.
filegroup() function returns the group ID of the specified file. The
filectime() function returns the last inode modification time of the specified file.
fileatime() function returns the last access time of the specified file.
file_put_contents() function writes a string to a file.
The file_get_contents() function reads the entire file into a string.
file_exists() function checks whether a file or directory exists. The
file() function reads the entire file into an array.
fgetss() function reads a line from an open file and filters out HTML and PHP tags.
fgets() function reads a line from the file pointer.
fgetcsv() function reads a line from the file pointer and parses the CSV field.
fgetc() function reads a character from the file pointer. The
fflush() function outputs the buffered content to a file. The
feof() function detects whether the end of file (eof) has been reached.
fclose() function closes an open file.
diskfreespace() function returns the free space in the directory. This function is an alias for the disk_free_space() function.
disk_total_space() function returns the total disk size of the specified directory.
disk_free_space() function returns the free space in the directory
dirname() function returns the directory part of the path.
clearstatcache() function copies files.
clearstatcache() function clears the file status cache.
chown() function changes the owner of the specified file.
chmod() function changes the file mode.
chgrp() function changes the group to which the file belongs.
The basename() function returns the file name part of the path.
set_exception_handler() handler() function

PHP Error and Logging function
set_exception_handler() function sets a user-defined exception handling function.
set_error_handler() function sets a user-defined error handling function.
The restore_exception_handler() function restores the previous exception handler, which was changed by the set_exception_handler() function.
The restore_error_handler() function restores the previous error handler, which was changed by the set_error_handler() function.
error_reporting() sets the error reporting level of PHP and returns the current level.
The error_log() function sends an error to the server error log, a file, or a remote destination.
error_get_last() function gets the last error that occurred.
debug_print_backtrace() function outputs backtrace.
debug_backtrace() cktrace() function

PHP Error and Logging function
scandir() function returns an array containing files and directories in the specified path.
rewinddir() function resets the directory handle opened by opendir(). The
readdir() function returns the entry in the directory handle opened by opendir(). The
opendir() function opens a directory handle and can be used by closedir(), readdir() and rewinddir().
getcwd() function returns the current directory. The
closedir() function closes the directory handle opened by the opendir() function. The
dir() function opens a directory handle and returns an object. This object contains three methods: read(), rewind() and close().
chroot() function changes the root directory of the current process to the specified directory.
chdir() function changes the current directory to the specified directory. The
time() function returns the Unix timestamp of the current time. The
strtotime() function parses any English text datetime description into a Unix timestamp.
strptime() function parses the date/time generated by strftime().
strftime() function formats local time/date according to locale settings. The
mktime() function returns the Unix timestamp of a date.
microtime() function returns the current Unix timestamp and microseconds.
localtime() function returns local time (an array).
idate() function formats local time/date into integers.
gmstrftime() function formats GMT/UTC time/date according to local locale settings. The
gmmktime() function gets the UNIX timestamp of the GMT date.
gmdate() function formats GMT/UTC date/time.
gettimeofday() function returns an array containing the current time information.
getdate() function obtains date/time information.
date() function formats a local time/date.
date_sunset() function returns the sunset time of the specified date and location.
date_sunrise() function returns the sunrise time of the specified date and location.
date_default_timezone_set() function sets the default time zone used for all date/time functions in scripts.
date_default_timezone_get() function returns the default time zone used by all date and time functions in the script.
checkdate() function verifies a Gregorian date.
UnixToJD() function converts Unix timestamp to Julian day count.
JulianToJD() function converts the Julian calendar into Julian day counting.
JewishToJD() function converts Jewish calendar to Julian day count.
JDToUnix() function converts Julian day count to Unix timestamp.
JDToGregorian() lian() function

PHP Array function
JDToGregorian() wish() function

PHP Array function
JDToGregorian() function converts the Julian day count to the Gregorian calendar.
The JDToFrench() function converts the Julian day count to the French Republic calendar.
JDMonthName() function returns the month string of the specified calendar.
JDDayOfWeek() function returns the day of the week the date is on.
GregorianToJD() function converts the Gregorian calendar to Julian day counting.
FrenchToJD() function converts the French Republican calendar into Julian day counting. The
easter_days() function returns the number of days between Easter and March 21 in the specified year. The
easter_date() function returns the Unix timestamp of Easter midnight in the specified year.
cal_to_jd() function converts the specified date to Julian day count. The
cal_info() function returns an array containing information about the given calendar. The
cal_from_jd() function converts the Julian day count to a date in the specified calendar. The
cal_days_in_month() function returns the number of days in a month for the specified year and calendar. The
usort() function sorts the array using a user-defined function. The
uksort() function uses a user-defined comparison function to sort the array by key name and maintain the index relationship. The
uasort() function sorts the array using a user-defined comparison function and maintains index association (no new keys are assigned to elements).
sort() function sorts the values ​​of the given array in ascending order.
sizeof() function counts the number of cells in an array or the number of attributes in an object. The
shuffle() function rearranges the elements in the array in random order. The
rsort() function sorts the elements of the array in reverse order by key value. Basically the same function as arsort(). The
reset() function sets the internal pointer of the array to the first element and returns the value of this element. The
range() function creates and returns an array containing elements in the specified range.
prev() HP prev() function

PHP Array function
pos() function is an alias of current() function. It returns the value of the current element in the array.
The next() function moves the pointer pointing to the current element to the position of the next element and returns the value of the current element. The
natsort() function sorts the elements in the given array using the natural order algorithm. The
natcasesort() function sorts the elements in the given array using a case-insensitive natural ordering algorithm. The
list() function assigns values ​​to a set of variables using elements in the array. The
ksort() function sorts the array by key name, retaining the original keys for the array values. The
krsort() function sorts the array in reverse order by key, retaining the original keys for the array values. The
key() function returns the key name of the element currently pointed to by the internal pointer of the array.
in_array() function searches an array for a given value.
extract() extract() function

PHP Array function
end() function points the internal array pointer to the last element and returns the value of that element (if successful). The
each() function generates an array consisting of the key name and key value of the element pointed to by the current internal pointer of the array, and moves the internal pointer forward.
current() function returns the current element (cell) in the array.
count() function counts the number of cells in an array or the number of attributes in an object. The
compact() function creates an array consisting of the variables taken by the parameters. If there is an array in the parameter, the value of the variable in the array will also be obtained.
asort() function sorts the array and maintains the index relationship. Mainly used for sorting associative arrays where the order of cells is important. The
arsort() function sorts the array in reverse order and maintains the index relationship. Mainly used for sorting associative arrays where the order of cells is important.
array_walk_recursive() cursive() function

PHP Array function
array_walk() function applies a callback function to each element in the array. Returns TRUE if successful, FALSE otherwise. The
array_values() function returns an array containing all key values ​​in the given array, but does not retain the key names.
array_unshift() function inserts one or more elements at the beginning of the array. The
array_unique() function removes duplicate values ​​from the array and returns the resulting array.
array_uintersect_assoc() function calculates the intersection of arrays with index check, and uses callback function to compare data.
array_uintersect() function calculates the intersection of arrays and uses callback functions to compare data.
array_udiff_uassoc() function returns the part that exists in the array1 array but does not exist in other arrays. The key names in the returned array remain unchanged.
array_udiff_assoc() function returns the part that exists in array1 but does not exist in other arrays. The
array_udiff() function returns an array that includes all values ​​in the compared array but not in any other parameter array, and the key names remain unchanged.
array_sum() function returns the sum of all values ​​in the array. The
array_splice() function is similar to the array_slice() function, selecting a series of elements in the array, but instead of returning them, it deletes them and replaces them with other values. The
array_slice() function takes out a segment of value from the array based on conditions and returns it.
array_shift() function deletes the first element in the array and returns the value of the deleted element.
array_search() function is the same as in_array(), searching for a key value in the array. If the value is found, the key of the matching element is returned. If not found, returns false.
array_reverse() function reverses the order of elements in the original array, creates a new array and returns it. If the second parameter is specified as true, the element's key name remains unchanged, otherwise the key name is lost. The
array_reduce() function uses a callback function to iteratively reduce an array to a single value. If a third argument is specified, it will be treated as the first value in the array, or as the final return value if the array is empty. The
array_rand() function randomly selects one or more elements from the array and returns it. The
array_push() function adds one or more elements (push) to the end of the array of the first parameter, and then returns the length of the new array.
array_product() function calculates and returns the product of all values ​​in an array.
array_pop() function deletes the last element in the array. The
array_pad() function inserts a specified number of elements with a specified value into an array.
array_multisort() function sorts multiple arrays or multidimensional arrays.
The array_merge_recursive() function is the same as the array_merge() function. It merges the elements of one or more arrays. The values ​​in one array are appended to the previous array. and returns the resulting array.
array_merge() function merges two or more arrays into one array.
array_map() function returns the array after the user-defined function is applied. The callback function should accept the same number of arguments as the number of arrays passed to the array_map() function. The
array_keys() function returns a new array containing all the keys in the array.
The array_key_exists() function determines whether the specified key exists in an array. If the key exists, it returns true, otherwise it returns false. The
array_intersect_ukey() function uses a callback function to compare key names to calculate the intersection of arrays. The
array_intersect_uassoc() function uses a user-defined callback function to calculate the intersection of arrays and uses the callback function to compare the indices. The
array_intersect_key() function uses key name comparison to calculate the intersection of arrays.
array_intersect_assoc() function returns the intersection array of two or more arrays.
array_intersect() function returns the intersection array of two or more arrays. The
array_flip() function returns a reversed array. If the same value appears multiple times, the last key name will be used as its value, and all other key names will be lost. The
array_filter() function uses a callback function to filter the elements in the array. If the custom filter function returns true, the current value of the operated array will be included in the returned result array, and the result will be formed into a new array. If the original array is an associative array, the key names remain unchanged. The
array_fill() function fills the array with the given value. The returned array has number elements and the value is value. The returned array is numerically indexed, starting at the start position and increasing. If number is 0 or less than 0, an error occurs.
array_diff_ukey() returns an array that contains the values ​​of all keys that appear in array1 but do not appear in any other parameter array. Note that the relationship remains unchanged. Unlike array_diff(), the comparison is based on keys rather than values. The
array_diff_uassoc() function uses a user-defined callback function to do index checking to calculate the difference between two or more arrays. Returns an array containing the values ​​in array1 but not in any of the other argument arrays. The
array_diff_key() function returns an array containing all keys that are in the compared array but are not in any other parameter array.
array_diff_assoc() function returns the difference array of two arrays. This array contains all keys and values ​​that are in the array being compared, but are not in any of the other argument arrays. The
array_diff() function returns the difference array of two arrays. This array contains all keys that are in the array being compared, but are not in any of the other argument arrays. The
array_count_values() function is used to count the number of occurrences of all values ​​in the array. The
array_combine() function creates a new array by merging two arrays, one of which is the key name, and the value of the other array is the key value.
array_chunk() function splits an array into new array chunks.
array_change_key_case() function converts all KEYs in the array to uppercase or lowercase.
array() creates an array with keys and values. If the key is omitted when specifying the array, an integer key is generated that starts at 0 and increments by 1.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template