PS: This table summarizes various commonly used PHP functions, including PHP string functions, array functions, math functions, MySQL functions, file/directory functions, GD library functions, SESSION functions, and Date/Time functions. It covers all kinds of commonly used functions involved in basic PHP operations, and provides simple explanations for each function for easy reference.
String-related operation functions |
|
Remove spaces or other characters |
|
|---|---|
| trim | 删除字符串 Both ends 空格或其他预定义字符 |
| rtrim | 删除字符串 right side 空格或其他预定义字符 |
| chop | rtrim() 的别名 chop() differs from Perl's chop() function as it removes the last character of the string. |
| ltrim | 删除字符串 Left 空格或其他预定义字符 |
String Generation and Conversion |
|
| str_pad | Fill the string to the specified length using another string. |
| str_split | Convert a string to an array |
| strrev | Reverse a string |
| wordwrap | Split a string into specified number of substrings |
| str_shuffle | Randomly shuffle a string |
| parse_str | Parse the string into variables |
| number_format | Format strings with thousands separator |
String case conversion |
|
| strtolower | convert string to lowercase |
| strtoupper | Convert string to uppercase |
| ucfirst | Capitalize the first letter of a string. |
| lcfirst | Convert the first letter of a string to lowercase. |
| ucwords | Capitalize the first letter of each word in the string. |
HTML tag association |
|
| htmlentities | Convert characters to HTML entities |
| htmlspecialchars | Predefined string to HTML encoding |
| nl2br | 在字符串所有新行之前插入 HTML 换行标记 n转换为<br>标签 |
| strip_tags | Remove HTML and PHP tags from a string |
| addcslashes | Using backslash escape characters in string literals in C style |
| stripcslashes | 反引用一个使用 addcslashes() 转义的字符串 |
| addslashes | Use backslash to quote strings |
| stripslashes | 删除由 addslashes 添加的转义字符 |
| quotemeta | Add a backslash before certain predefined strings in a string. |
| chr | 从指定的 ASCII 值返回字符 |
| ord | 返回字符串第一个字符的 ASCII 值 |
String comparison |
|
| strcasecmp | Case-insensitive comparison of two strings |
| strcmp | Case-sensitive comparison of two strings |
| strncmp | 比较字符串前N个字符,区分大小写 |
| strncasecmp | Compare the first N characters of the strings, case-insensitively |
| strnatcmp | Natural order method compares string lengths, case-sensitive |
| strnatcasecmp | Natural order method compares string lengths, case-insensitive |
String search and replace |
|
| str_replace | String replacement, case-sensitive |
| str_ireplace | Case-insensitive string replacement operation |
| substr_count | 统计一个字符串,在另一个字符串中出现的次数 |
| substr_replace | Replace a substring with another string |
| similar_text | Return the count of common characters between two strings. |
| strrchr | Return the substring from the last occurrence of a string to the end of another string. |
| strstr | Return the substring from the beginning to the end within another string. |
| strchr | Alias of strstr, returns a substring starting from the first occurrence of one string within another until the end |
| stristr | Return a substring from another string starting at the beginning position to the end position, case-insensitive. |
| strtr | Translate certain characters in a string |
| strpos | Find the first occurrence position of certain characters in a string |
| stripos | Find the first occurrence position of certain characters in a string, case-insensitive. |
| strrpos | Find the last occurrence position of certain characters in a string |
| strripos | Find the last occurrence position of certain characters in a string, case-insensitive. |
| strspn | Return the length of the first substring that matches the mask in the given string. |
| strcspn | Return the length of the string that does not match the mask. |
String Statistics |
|
| str_word_count | Count the number of words in a string |
| strlen | Count string length |
| count_chars | 统计字符串中所有字母出现的次数(0..255) |
String encoding |
|
| md5 | Calculate the MD5 hash of a string |
| hash | Generate a hash code. |
Array-related functions |
|
Create an array |
|
| array | Create an array. |
| array_combine | Generate an array where one array's values serve as keys and the other as values. |
| range | Create and return an array containing elements within a specified range. |
| compact | Create an array composed of variables carried by parameters. |
| array_fill | Fill the generated array with given values. |
Array merging and splitting |
|
| array_chunk | Split an array into new array blocks |
| array_merge | Merge two or more arrays into one array. |
| array_slice | Extract a segment of values from an array based on conditions and return them. |
Array comparison |
|
| array_diff | Return the difference set array of two arrays |
| array_intersect | Return the intersection array of two or more arrays |
Array Search and Replace |
|
| array_search | Find a key value in an array |
| array_splice | Remove part of the array and replace the rest. |
| array_sum | Return the sum of all values in the array. |
| in_array | Search for a specified value in an array, case sensitive |
| array_key_exists | Check if a specified key exists in an array |
Array pointer operations |
|
| key | Return the key name currently pointed to by the internal pointer of the array. |
| current | Return the current element in the array |
| next | Move the pointer to the next element's position and return the current element's value. |
| prev | Move the pointer to the previous element and return the value of the current element. |
| end | 将数组内部指针指向最后一个元素,并返回该元素的值 (If successful) |
| reset | Set the internal pointer of the array to point to the first element and return its value. |
| list | Assign values to variables using elements from an array. |
| array_shift | Remove the first element from the array and return its value. |
| array_unshift | Insert one or more elements at the beginning of an array |
| array_push | Push one or more elements to the end of the array |
| array_pop | Remove the last element of the array |
Array key operations |
|
| shuffle | Shuffle array while retaining key names. |
| count | Calculate the number of elements in an array or the number of properties in an object. |
| array_flip | Return an array with keys and values flipped. |
| array_keys | Return all keys of the array as an array. |
| array_values | 返回数组所有值,组成一个数组 |
| array_reverse | Return an array with elements in reverse order. |
| array_count_values | Count the occurrences of all values in the array |
| array_rand | Randomly select one or more elements from the array, note that it is the key name. |
| each | Return the current key/value pair from the array and move the array pointer forward by one step. |
| array_unique | Remove duplicate values from an array. |
Array sorting |
|
| sort | Sort the array |
| rsort | Reverse sort the array |
| asort | Sort the array while maintaining the index relationships |
| arsort | Reverse sort the array while maintaining index relationships |
| ksort | Sort array by key name |
| krsort | Sort the array by key name in reverse order |
| natsort | Sort the array using the "Natural Sorting" algorithm. |
| natcasesort | Sort the array using a "natural sort" algorithm, case-insensitive. |
Mathematical related functions |
|
| abs | Find the absolute value |
| ceil | Round up to the next integer |
| floor | Discarding and rounding down |
| fmod | Return the floating-point remainder of a division. |
| pow | Return the Nth power of a number |
| round | Floating-point rounding method |
| sqrt | Find the square root |
| max | Maximize |
| min | Minimize |
| mt_rand | Better random number |
| rand | Random number |
| pi | Obtain Pi |
| octdec | Octal to decimal conversion |
MySQL-related functions |
|
| mysql_affected_rows | Get the number of rows affected by the previous MySQL operation. |
| mysql_client_encoding | Return the name of the character set |
| mysql_close | Close MySQL connection |
| mysql_connect | Establish a connection to the MySQL server. |
| mysql_create_db | Create a new MySQL database |
| mysql_data_seek | Move the pointer to the internal result |
| mysql_db_name | Obtain result data |
| mysql_db_query | Send a MySQL query |
| mysql_drop_db | Drop a MySQL database |
| mysql_errno | Return the numeric code for the error information of the previous MySQL operation. |
| mysql_error | Return the text error message produced by the last MySQL operation. |
| mysql_escape_string | Escape a string for use with mysql_query |
| mysql_fetch_array | Retrieve a row from the result set as an associative array, or a numeric array, or both. |
| mysql_fetch_assoc | Retrieve a row from the result set as an associative array |
| mysql_fetch_field | Retrieve column information from a result set and return it as an object. |
| mysql_fetch_lengths | Get the length of each output in the result set. |
| mysql_fetch_object | Fetch a row from the result set as an object. |
| mysql_fetch_row | Retrieve a single row from a result set as an enumeration array |
| mysql_field_flags | Extract flags associated with specified fields from the results. |
| mysql_field_len | Return the length of a specified field. |
| mysql_field_name | Get the field name of the specified field in the result |
| mysql_field_seek | Set the pointer in the result set to the specified field offset. |
| mysql_field_table | Get the table name where the specified field is located |
| mysql_field_type | Get the type of a specified field in the result set. |
| mysql_free_result | Release result memory |
| mysql_get_client_info | Retrieve MySQL client information |
| mysql_get_host_info | Retrieve MySQL host information |
| mysql_get_proto_info | Retrieve MySQL protocol information |
| mysql_get_server_info | Retrieve MySQL server information |
| mysql_info | Retrieve the information of the latest query. |
| mysql_insert_id | Obtain the ID generated by the previous INSERT operation |
| mysql_list_dbs | List all databases in the MySQL server. |
| mysql_list_fields | List fields in MySQL result |
| mysql_list_processes | List MySQL processes |
| mysql_list_tables | List the tables in the MySQL database. |
| mysql_num_fields | Get the number of fields in the result set |
| mysql_num_rows | Get the number of rows in the result set. |
| mysql_pconnect | Establish a persistent connection to a MySQL server |
| mysql_ping | Ping a server connection, and reconnect if not connected. |
| mysql_query | Send a MySQL query |
| mysql_real_escape_string | Escape special characters in the string used in SQL statements, taking into account the current connection character set. |
| mysql_result | Obtain result data |
| mysql_select_db | Select MySQL database |
| mysql_set_charset | Sets the client character set |
| mysql_stat | Get current system status |
| mysql_tablename | Get table name |
| mysql_thread_id | Return the current thread's ID |
| mysql_unbuffered_query | Send an SQL query to MySQL without fetching and caching the rows of the result |
File directory handling functions |
|
| basename | Return the filename part from the path. |
| chgrp | Change file group ownership |
| chmod | Change file mode |
| chown | Change file owner |
| clearstatcache | Clear file status cache |
| copy | Copy file |
| delete | See unlink or unset. |
| dirname | The directory part in the path returned. |
| disk_free_space | Return to the directory's available space. |
| disk_total_space | Return the total disk size of a directory |
| diskfreespace | alias for disk_free_space: available disk space |
| fclose | Close an open file pointer |
| feof | Check if the file pointer has reached the end of the file |
| fflush | Output buffered content to file |
| fgetc | Read characters from a file pointer. |
| fgetcsv | Read a line from a file pointer and parse CSV fields |
| fgets | Read a line from a file pointer |
| fgetss | Read a line from a file pointer and filter out HTML tags. |
| file_exists | Check if file or directory exists |
| file_get_contents | Read the entire file into a string |
| file_put_contents | Write a string to a file. |
| file | Read the entire file into an array. |
| fileatime | Get the last access time of the file. |
| filectime | Get the inode modification time of the file |
| filegroup | Gaining access to the file group |
| fileinode | Obtain file's inode |
| filemtime | Get file modification time |
| fileowner | Acquire the owner of the file |
| fileperms | Get file permissions |
| filesize | Get file size |
| filetype | Retrieve file type |
| flock | Lightweight consultation document locked |
| fnmatch | Match files by pattern |
| fopen | Open file or URL |
| fpassthru | All remaining data at the output file pointer |
| fputcsv | Format rows as CSV and write to file pointer |
| fputs | alias of fwrite |
| fread | Read file (safe for binary files) |
| fscanf | Format input from file |
| fseek | Locate in file pointer |
| fstat | Obtain file information through an open file pointer. |
| ftell | Return the file pointer to the read/write position. |
| ftruncate | Truncate file to a given length |
| fwrite | Write to file (safe for binary files) |
| glob | Find file paths matching the pattern |
| is_dir | Determine if a given filename is a directory |
| is_executable | Check if a given filename is executable |
| is_file | Determine if a given filename is a normal file. |
| is_link | Check if the given filename is a symbolic link |
| is_readable | Check if the given filename is readable |
| is_uploaded_file | Determine if a file was uploaded via HTTP POST |
| is_writable | Check if the given filename is writable. |
| is_writeable | is_writable alias |
| lchgrp | Changes group ownership of symlink |
| lchown | Changes user ownership of symlink |
| link | Establish a hard link |
| linkinfo | Get the information of a connection |
| lstat | Provide information about a file or symbolic link. |
| md5_file | Calculate the MD5 hash of a file |
| mkdir | Create new directory |
| move_uploaded_file | Move uploaded file to a new location. |
| parse_ini_file | Parse a configuration file |
| parse_ini_string | Parse a configuration string |
| pathinfo | Return the file path information. |
| pclose | Close process file pointers |
| popen | Open process file pointer |
| readfile | Output a file |
| readlink | Return the target of the symbolic link. |
| realpath_cache_get | Get realpath cache entries |
| realpath_cache_size | Get realpath cache size |
| realpath | Return normalized absolute path name |
| rename | Rename a file or directory |
| rewind | rewind file pointer |
| rmdir | Delete directory |
| set_file_buffer | alias of stream_set_write_buffer |
| stat | Provide file information. |
| symlink | Establish symbolic links |
| tempnam | Create a file with a unique filename. |
| tmpfile | Create a temporary file |
| touch | Set file access and modification times |
| umask | Change the current umask. |
| unlink | Delete file |
GD/Image function |
|
| gd_info | Retrieve information about the currently installed GD library. |
| getimagesize | Get image size |
| getimagesizefromstring | Get the size of an image from a string |
| image_type_to_extension | File extension for image types |
| image_type_to_mime_type | Retrieve the MIME type of the image from the return values of getimagesize(), exif_read_data(), exif_thumbnail(), and exif_imagetype(). |
| image2wbmp | Output image in WBMP format to a browser or file |
| imagealphablending | Set the image's blending mode. |
| imageantialias | Is antialiasing enabled? |
| imagearc | Draw an elliptical arc |
| imagechar | Draw a character horizontally. |
| imagecharup | Draw a character vertically |
| imagecolorallocate | Assign colors to an image |
| imagecolorallocatealpha | Assign colors + alpha to an image |
| imagecolorat | Get the color index value of a pixel. |
| imagecolorclosest | Get the index value of the color closest to the specified color. |
| imagecolorclosestalpha | Find the closest color with specified opacity. |
| imagecolorclosesthwb | Find the index of the shade closest to the given color in grayscale. |
| imagecolordeallocate | Cancel image color assignment |
| imagecolorexact | Get the index value of a specified color. |
| imagecolorexactalpha | Obtain the index value for a specified color with transparency. |
| imagecolormatch | Make the palette version of an image's colors more closely match the true color version. |
| imagecolorresolve | Obtain the index value of a specified color or the closest alternative if possible. |
| imagecolorresolvealpha | Obtain the index value of the specified color + alpha, or the closest substitute if possible. |
| imagecolorset | Set color for specified palette index |
| imagecolorsforindex | Get the color of an index |
| imagecolorstotal | Obtain the number of colors in an image's palette |
| imagecolortransparent | Define a color as transparent. |
| imageconvolution | Apply a 3x3 convolutional matrix using coefficient div and offset. |
| imagecopy | Copy a part of the image. |
| imagecopymerge | Copy and merge a portion of an image |
| imagecopymergegray | Merge a portion of an image using grayscale copy. |
| imagecopyresampled | Resample and copy a portion of the image and adjust the size. |
| imagecopyresized | Copy and resize part of the images |
| imagecreate | Create a new image based on a palette |
| imagecreatefromgd2 | Create an image from a GD2 file or URL |
| imagecreatefromgd2part | Create a new image from part of the given GD2 file or URL. |
| imagecreatefromgd | Create an image from a GD file or URL. |
| imagecreatefromgif | Create a new image from a file or URL |
| imagecreatefromjpeg | Create a new image from a file or URL |
| imagecreatefrompng | Create a new image from a file or URL |
| imagecreatefromstring | Create a new image from a string-based image stream |
| imagecreatefromwbmp | Create a new image from a file or URL |
| imagecreatefromxbm | Create a new image from a file or URL |
| imagecreatefromxpm | Create a new image from a file or URL |
| imagecreatetruecolor | Create a true-color image |
| imagedashedline | Draw a dashed line. |
| imagedestroy | Destroy an image. |
| imageellipse | Draw an ellipse. |
| imagefill | Regional filling |
| imagefilledarc | Draw an ellipse arc and fill it |
| imagefilledellipse | Draw and fill an ellipse |
| imagefilledpolygon | Draw a polygon and fill it |
| imagefilledrectangle | Draw a rectangle and fill it. |
| imagefilltoborder | Fill region to the boundary of specified color |
| imagefilter | Apply a filter to the image. |
| imagefontheight | Get font height |
| imagefontwidth | Obtain font width |
| imageftbbox | Create a text box using the FreeType 2 font. |
| imagefttext | Write text into an image using FreeType 2 font |
| imagegammacorrect | Apply gamma correction to the GD image. |
| imagegd2 | Output GD2 image to browser or file |
| imagegd | Output GD image to browser or file |
| imagegif | Output image to browser or file |
| imagegrabscreen | Captures the whole screen |
| imagegrabwindow | Captures a window |
| imageinterlace | Activate or disable interlaced scanning |
| imageistruecolor | Check if the image is a true color image. |
| imagejpeg | Output image to browser or file |
| imagelayereffect | Set the alpha blending flag to use the bound libgd layer effects. |
| imageline | Draw a line segment. |
| imageloadfont | Load a new font. |
| imagepalettecopy | Copy the palette from one image to another. |
| imagepng | Output image in PNG format to browser or file |
| imagepolygon | Draw a polygon. |
| imagepsbbox | Create a text box using a PostScript Type1 font. |
| imagepsencodefont | Change the character encoding vector in the font |
| imagepsextendfont | Expand or condense font size |
| imagepsfreefont | Release the memory occupied by a PostScript Type 1 font. |
| imagepsloadfont | Load a PostScript Type 1 font from a file. |
| imagepsslantfont | Tilt a font |
| imagepstext | Draw text string on image using PostScript Type1 font. |
| imagerectangle | Draw a rectangle. |
| imagerotate | Rotate image by given angle. |
| imagesavealpha | Set a flag to save full alpha channel information when saving PNG images (as opposed to a single transparent color). |
| imagesetbrush | Set the line drawing pen image |
| imagesetpixel | Draw a single pixel. |
| imagesetstyle | Set the line style |
| imagesetthickness | Set line width |
| imagesettile | Texture set for filling |
| imagestring | Draw a string horizontally. |
| imagestringup | Draw a string vertically |
| imagesx | Get image width |
| imagesy | Get image height |
| imagetruecolortopalette | Convert true-color images to palette images |
| imagettfbbox | Range of text using TrueType fonts |
| imagettftext | Write text to an image using TrueType font |
| imagetypes | Retrieve the image types supported by the current PHP version. |
| imagewbmp | Output image in WBMP format to a browser or file |
| imagexbm | Output XBM image to browser or file |
| iptcembed | Embed binary IPTC data into a JPEG image |
| iptcparse | Parse the binary IPTC block at http://www.iptc.org/ into individual tags. |
| jpeg2wbmp | Convert JPEG image files to WBMP image files. |
| png2wbmp | Convert PNG image file to WBMP image file |
session function |
|
| session_cache_expire | Return current cache expiration |
| session_cache_limiter | get and set the current cache limit/limit |
| session_commit | alias for session_write_close: session_close |
| session_decode | Session data from a session-encoded string |
| session_destroy | Destroy all data registered to the session. |
| session_encode | Encode the current session data into a string |
| session_get_cookie_params | Retrieve session cookie parameters |
| session_id | Get and/or set current session ID |
| session_is_registered | Check if the variable is already registered in the session. |
| session_module_name | Access and/or set the current session module |
| session_name | Get and/or set the current session name |
| session_regenerate_id | Update the newly generated session identifier |
| session_register_shutdown | Session shutdown feature |
| session_register | Register one or more global variables with the current session. |
| session_save_path | Get and/or set the current session save path |
| session_set_cookie_params | Set session cookie parameters |
| session_set_save_handler | Set user-level session storage feature |
| session_start | Start a new or resume an existing session |
| session_status | Return current session state |
| session_unregister | Terminate the global variable of the current session |
| session_unset | Free all session variables |
| session_write_close | Write session data and end session. |
cookie function |
|
| setcookie() | Set cookie |
| setrawcookie | Send a cookie without URL encoding |
Date/Time function |
|
| checkdate | Verify a Gregorian date |
| date_add | Alias DateTime::add |
| date_create_from_format | Alias DateTime::createFromFormat |
| date_create | Alias DateTime::__construct |
| date_date_set | Alias DateTime::setDate |
| date_default_timezone_get | Retrieve the default timezone used by all datetime functions in a script. |
| date_default_timezone_set | Set the default timezone for all datetime functions in the script. |
| date_diff | Alias DateTime::diff |
| date_format | Alias DateTime::format |
| date_get_last_errors | Alias DateTime::getLastErrors |
| date_interval_create_from_date_string | Alias DateInterval::createFromDateString |
| date_interval_format | Alias DateInterval::format |
| date_isodate_set | Alias DateTime::setISODate |
| date_modify | Alias DateTime::modify |
| date_offset_get | Alias DateTime::getOffset |
| date_parse_from_format | Get info about given date formatted according to the specified format |
| date_parse | Returns associative array with detailed info about given date |
| date_sub | Alias DateTime::sub |
| date_sun_info | Returns an array with information about sunset/sunrise and twilight begin/end |
| date_sunrise | Return the sunrise time for the given date and location. |
| date_sunset | Return the sunset time for the given date and location. |
| date_time_set | Alias DateTime::setTime |
| date_timestamp_get | Alias DateTime::getTimestamp |
| date_timestamp_set | Alias DateTime::setTimestamp |
| date_timezone_get | Alias DateTime::getTimezone |
| date_timezone_set | Alias DateTime::setTimezone |
| date | Format a local date/time |
| getdate | Retrieve date/time information |
| gettimeofday | Get current time |
| gmdate | Format a GMT/UTC date/time |
| gmmktime | Get the UNIX timestamp for the GMT date. |
| gmstrftime | Format GMT/UTC time/date based on regional settings |
| idate | Format local date and time as an integer |
| localtime | Get local time |
| microtime | Return the current Unix timestamp and microseconds |
| mktime | Obtain a Unix timestamp for a date |
| strftime | Format local time/date based on region settings |
| strptime | Decoding the date/time generated by strftime |
| strtotime | Parse any English text that describes a date and time into a Unix timestamp. |
| time | Return the current Unix timestamp. |
| timezone_abbreviations_list | Alias DateTimeZone::listAbbreviations |
| timezone_identifiers_list | Alias DateTimeZone::listIdentifiers |
| timezone_location_get | Alias DateTimeZone::getLocation |
| timezone_name_from_abbr | Returns the timezone name from abbreviation |
| timezone_name_get | Alias DateTimeZone::getName |
| timezone_offset_get | Alias DateTimeZone::getOffset |
| timezone_open | Alias DateTimeZone::__construct |
| timezone_transitions_get | Alias DateTimeZone::getTransitions |
| timezone_version_get | Gets the version of the timezonedb |
You recently used: