Home > Backend Development > PHP Tutorial > PHP common functions [Part 1]

PHP common functions [Part 1]

巴扎黑
Release: 2016-11-12 10:07:42
Original
1221 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. We have collected them below The most commonly used functions when developing PHP, I hope it will be helpful to you.

Recorded some common functions of PHP
usleep() function delays code execution for a few microseconds. The
unpack() function unpacks data from a binary string. The
uniqid() function generates a unique ID based on the current time in microseconds.
time_sleep_until() function delays code execution until the specified time.
time_nanosleep() function delays code execution for a number of seconds and nanoseconds. The
sleep() function delays code execution for a few seconds.
show_source() function performs syntax highlighting on files. The
strip_whitespace() function returns the source code file with PHP comments and whitespace characters removed. The
pack() function loads data into a binary string.
ignore_user_abort() function sets whether disconnecting from the client will terminate the execution of the script.
highlight_string() function performs syntax highlighting on strings.
highlight_file() function performs syntax highlighting on files.
get_browser() function returns the performance of the user's browser. The
exit() function outputs a message and exits the current script. The
eval() function calculates the string according to the PHP code. The
die() function outputs a message and exits the current script.
defined() function checks whether a constant exists.
define() function defines a constant.
constant() function returns the value of a constant. The
connection_status() function returns the current connection status.
connection_aborted() function checks whether the client is disconnected.
zip_read() function reads the next file in the opened zip archive.
zip_open() function opens a ZIP file for reading.
zip_entry_read() function gets the contents from the opened zip archive entry.
zip_entry_open() function opens a ZIP archive entry for reading.
zip_entry_name() function returns the name of the zip archive entry.
zip_entry_filesize() function returns the original size of the zip archive entry (before compression).
zip_entry_compressionmethod() function returns the compression method of the zip archive entry.
zip_entry_compressedsize() function returns the compressed file size of the zip archive entry.
zip_entry_close() function closes the zip archive file opened by zip_entry_open() function.
zip_close() function closes the zip archive file opened by zip_open() function.
xml_set_unparsed_entity_decl_handler() function specifies the function to be called when an unresolved entity name (NDATA) declaration is encountered. The
xml_set_processing_instruction_handler() function specifies the function to be called when the parser finds a processing instruction in the XML document.
xml_set_object() function allows using XML parser in objects. The
xml_set_notation_decl_handler() function specifies the function to be called when the parser finds a symbol declaration in the XML document. The
xml_set_external_entity_ref_handler() function specifies the function to be called when the parser finds an external entity in the XML document.
xml_set_element_handler() function establishes the starting and ending element handlers.
xml_set_default_handler() function establishes the default data handler for the XML parser.
xml_set_character_data_handler() function creates a character data handler.
xml_parser_set_option() function sets options for the XML parser.
xml_parser_get_option() function gets option setting information from XML parser.
xml_parser_free() function frees the XML parser.
xml_parser_create() function creates an XML parser.
xml_parser_create_ns() function creates an XML parser with namespace support.
xml_parse_into_struct() function parses XML data into an array.
xml_parse() function parses XML documents.
xml_get_error_code() function gets the XML parser error code.
xml_get_current_line_number() function gets the current line number of the XML parser.
xml_get_current_column_number() function gets the current column number of the XML parser.
xml_get_current_byte_index() function gets the current byte index of the XML parser.
xml_error_string() function gets the error description of the XML parser.
utf8_encode() function encodes ISO-8859-1 string into UTF-8.
utf8_decode() function decodes UTF-8 string to ISO-8859-1. The
wordwrap() function wraps the string according to the specified length.
vsprintf() function writes the formatted string into a variable.
vprintf() function outputs a formatted string.
vfprintf() function writes the formatted string to the specified output stream. The
ucwords() function converts the first character of each word in the string to uppercase.
ucfirst() function converts the first character in a string to uppercase.
The trim() function removes whitespace characters and other predefined characters from both ends of a string.
substr_replace() function replaces part of a string with another string.
substr_count() function counts the number of times a substring appears in a string.
substr_compare() function compares two strings from a specified starting length.
substr() function returns a part of a string.
strtr() function converts specific characters in a string.
strtoupper() function converts a string to uppercase.
strtolower() function converts string to lowercase.
strtok() function splits a string into smaller strings.
strstr() function searches for the first occurrence of a string in another string.
strspn() function returns the number of specific characters contained in a string.
strrpos() function finds the last occurrence of a string in another string.
strripos() function finds the last occurrence of a string within another string.
strrev() function reverses a string. The
strrchr() function finds the last occurrence of a string in another string and returns all characters from that position to the end of the string.
strpos() function returns the position of the first occurrence of a string in another string.
strpbrk() function searches for any one of the specified characters in the string.
strncmp() function compares two strings.
strncasecmp() function compares two strings. The
strnatcmp() function uses a "natural" algorithm to compare two strings.
The strnatcasecmp() function uses a "natural" algorithm to compare two strings.
strlen() function returns the length of the string.
stristr() function finds the first occurrence of a string in another string. The
stripos() function returns the position of the first occurrence of a string in another string.
stripslashes() function removes backslashes added by addslashes() function.
stripcslashes() function removes backslashes added by addcslashes() function.
strip_tags() function strips HTML, XML and PHP tags.
strcspn() function returns the number of characters searched in the string before any specified character is found.
strcoll() function compares two strings.
strcmp() function compares two strings.
strchr() function searches for the first occurrence of a string in another string.
strcasecmp() function compares two strings.
str_word_count() function counts the number of words in a string.
str_split() function splits a string into an array.
str_shuffle() function randomly shuffles all characters in a string.
str_rot13() function performs ROT13 encoding on a string.
str_replace() function uses a string to replace other characters in a string.
str_repeat() function repeats a string a specified number of times.
str_pad() function pads the string to the specified length.
str_ireplace() function uses a string to replace other characters in a string. The
sscanf() function parses input from a string according to the specified format. The
sprintf() function writes the formatted string into a variable.
soundex() function calculates the soundex key of a string.
similar_text() function counts the number of matching characters in two strings. The
sha1_file() function calculates the SHA-1 hash of a file. The
sha1() function calculates the SHA-1 hash of a string.
setlocale() function sets regional information (regional information).
rtrim() P rtrim() function
PHP String function
quotemeta() function adds a backslash before some predefined characters in the string. The
quoted_printable_decode() function decodes the quoted-printable encoded string and returns an 8-bit string.
The printf() function outputs a formatted string.
The print() function outputs one or more strings.
parse_str() function parses the query string into variables. The
ord() function returns the ASCII value of the first character of the string.
number_format() function formats numbers by thousands grouping. The
nl2br() function inserts an HTML newline character (
) before each new line (n) in a string.
nl_langinfo() function returns the specified local information.
money_format() function formats a string into a currency string. The
metaphone() function calculates the metaphone key of a string.
md5_file() function calculates the MD5 hash of a file.
md5() function calculates the MD5 hash of a string.
ltrim() function removes spaces or other predefined characters from the left side of a string.
localeconv() function returns an array containing local number and currency information format.
levenshtein() function returns the Levenshtein distance between two strings. The
join() function combines array elements into a string. The
implode() function combines array elements into a string.
The htmlspecialchars() function converts some predefined characters into HTML entities.
html_entity_decode() chars_decode() function

PHP String function
htmlentities() function converts characters into HTML entities.
html_entity_decode() function converts HTML entities into characters. The
hebrevc() function converts Hebrew text from right-to-left flow to left-to-right flow. It also converts newlines (n) to
. The
hebrev() function converts Hebrew text from right-to-left flow to left-to-right flow.
get_html_translation_table() function returns the translation table used by htmlentities() and htmlspecialchars() functions.
fprintf() function writes the formatted string to the specified output stream (for example: file or database).
explode() function splits a string into an array.
echo() function outputs one or more strings.
crypt() function returns a string encrypted using DES, Blowfish or MD5.
crc32() function calculates the crc32 polynomial of a string. The
count_chars() function returns information about the characters used in the string. The
convert_uuencode() function uses the uuencode algorithm to encode a string. The
convert_uudecode() function decodes uuencode-encoded strings.
convert_cyr_string() function converts characters from one Cyrillic character to another.
chunk_split() function splits a string into a series of smaller parts. The
chr() function returns the character from the specified ASCII value.
chop() function removes whitespace characters or other predefined characters starting from the end of the string. The
bin2hex() function converts a string of ASCII characters into a hexadecimal value. The
addslashes() function adds a backslash before the specified predefined characters.
addcslashes() function adds a backslash before the specified character. The
xpath() function runs an XPath query on an XML document.
simplexml_load_string() function loads an XML string into an object.
simplexml_load_file() function loads the XML document into the object.
simplexml_import_dom() function converts DOM nodes into SimpleXMLElement objects.
registerXPathNamespace() function creates a namespace context for the next XPath query.
getNamespace() function gets the namespace used in the XML document.
getName() function gets the name of XML element from SimpleXMLElement object. The
getDocNamespaces() function returns the namespaces declared in the XML document from the SimpleXMLElement object.
children() function gets the child nodes of the specified node. The
attributes() function gets the attributes of a SimpleXML element. The
asXML() function returns an XML document from a SimpleXMLElement object as a string. The
addChild() function adds a child node to the specified XML node. The
addAttribute() function adds an attribute to the SimpleXML element.
__construct() function creates a new SimpleXMLElement object.
The mysql_unbuffered_query() function sends a SQL query to MySQL (without getting/caching the results).
mysql_thread_id() function returns the ID of the current thread.
mysql_stat() function returns the current system status of the MySQL server.
The mysql_select_db() function sets the active MySQL database.
mysql_result() function returns the value of a field in the result set.
mysql_real_escape_string() function escapes special characters in strings used in SQL statements.
mysql_query() function executes a MySQL query.
mysql_ping() function Pings a server connection, and reconnects if there is no connection.
The mysql_pconnect() function opens a persistent connection to the MySQL server.
mysql_num_rows() function returns the number of rows in the result set.
mysql_num_fields() function returns the number of fields in the result set.
mysql_list_processes() function lists MySQL processes.
mysql_list_dbs() function lists all databases in the MySQL server. The
mysql_insert_id() function returns the ID generated by the previous INSERT operation.
mysql_info() function returns the information of the latest query.
mysql_get_server_info() function returns MySQL server information.
mysql_get_proto_info() function returns MySQL protocol information.
The mysql_get_host_info() function returns the MySQL host information.
mysql_get_client_info() function returns MySQL client information.
mysql_free_result() function releases the result memory.
mysql_field_type() function returns the type of the specified field in the result set.
mysql_field_table() function returns the table name where the specified field is located. The
mysql_field_seek() function sets the pointer in the result set to the specified field offset.
mysql_field_name() function gets the field name of the specified field in the result.
mysql_field_len() function returns the length of the specified field. The
mysql_field_flags() function obtains the flags associated with the specified field from the result.
The mysql_fetch_row() function fetches a row from the result set as a numeric array.
The mysql_fetch_object() function obtains a row as an object from the result set (record set).
mysql_fetch_lengths() function gets the length of the content of each field in a row.
The mysql_fetch_field() function obtains column information from the result set and returns it as an object.
The mysql_fetch_assoc() function fetches a row from the result set as an associative array.
mysql_fetch_array() function fetches a row from the result set as an associative array, a numeric array, or both
mysql_error() function returns the text error message generated by the previous MySQL operation. The
mysql_errno() function returns the numeric code of the error message in the previous MySQL operation.
The mysql_db_name() function obtains the database name returned by the mysql_list_dbs() call.
mysql_data_seek() function moves the pointer of the internal result.
mysql_connect() function opens a non-persistent MySQL connection.
mysql_close() function closes non-persistent MySQL connections. The
mysql_client_encoding() function returns the name of the character set of the current connection.
The mysql_affected_rows() function returns the number of record rows affected by the previous MySQL operation. The
tanh() function returns the hyperbolic tangent.
tan() function returns tangent. The
srand() function seeds the random number generator.
sqrt() function returns the square root of a number. The
sinh() function returns the hyperbolic sine of a number. The
sin() function returns the sine of a number.
round() function rounds floating point numbers.
rand() function returns a random integer.
rad2deg() function converts radians to degrees. The
pow() function returns x raised to the yth power. The
pi() function returns the value of pi.
octdec() function converts octal to decimal.
mt_srand() seeds the Mersenne Twister random number generator.
mt_rand() returns a random integer using the Mersenne Twister algorithm.
mt_getrandmax() displays the maximum possible value of a random number.
min() returns the minimum value.
max() returns the maximum value.
log1p() to return log(1 + x), which can be calculated accurately even when the value of x is close to zero.
log10() Logarithm to base 10.
log() returns the natural logarithm.
lcg_value() combines linear congruential generators.
is_nan() determines whether it is a legal value.
is_infinite() determines whether it is infinite.
is_finite() function determines whether it is a finite value.
hypot() function calculates the length of the hypotenuse of a right triangle.
hexdec() function converts hexadecimal to decimal.
fmod() function displays the largest possible value of a random number.
fmod() function returns the floating point remainder of division.
floor() function rounds down to the nearest integer.
expm1() function returns exp(x) - 1, which can be calculated accurately even when the value of number is close to zero. The
exp() function calculates the exponent of e.
deg2rad() function converts angles to radians.
decoct() function converts decimal to octal.
dechex() function converts decimal to hexadecimal.
decbin() function converts decimal to binary. The
cosh() function returns the hyperbolic cosine of a number. The
cos() function returns the cosine of a number.
ceil() function rounds up to the nearest integer.
bindec() function converts binary to decimal.
base_convert() function converts numbers between arbitrary bases. The
atanh() function returns the inverse hyperbolic tangent of an angle.
atan() and atan2() and atan2() function

PHP Math function
atan() and atan2() and atan2() function

PHP Math function
asinh() function returns the inverse hyperbolic sine of a number. The
asin() function returns the arcsine of different values. The returned result is a radian value between -PI/2 and PI/2. The
acosh() function returns the inverse hyperbolic cosine of a number.

Related labels:
php
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