Loading... # PHP String Functions The following section contains a list of PHP string functions along with a brief description. ## PHP String Functions Here is a complete list of string functions belonging to the latest PHP 7. These functions are the part of the PHP core so you can use them within your script without any further installation. addcslashes() Returns a string with backslashes before the specified characters. --- addslashes() Returns a string with backslashes before the characters that need to be escaped. These characters are single quote (‘), double quote (“), backslash () and NULL. --- bin2hex() Convert binary data into hexadecimal values. --- chop() Strip whitespace (or other characters) from the end of a string. Alias of rtrim() function. --- chr() Returns a one-character string containing the character specified by ASCII. --- chunk\_split() Split a string into smaller chunks. --- convert\_cyr\_string() Converts a string from one Cyrillic character set to another. --- convert\_uudecode() Decodes a uuencoded string. --- convert\_uuencode() Encodes a string using the uuencode algorithm. --- count\_chars() Returns information about characters used in a string. --- crc32() Calculates the crc32 polynomial of a string. --- crypt() One-way string encryption (or hashing). --- echo() Outputs one or more strings. --- explode() Split a string into an array by a specified string. --- fprintf() Write a formatted string to a specified output stream. --- get\_html\_translation\_table() Returns the translation table used by htmlspecialchars() and htmlentities() --- hebrev() Convert logical Hebrew text to visual text. --- hex2bin() Decodes a hexadecimally encoded binary string. --- html\_entity\_decode() Convert all HTML entities to their applicable characters. --- htmlentities() Convert all applicable characters to HTML entities. --- htmlspecialchars\_decode() Convert special HTML entities back to characters. --- htmlspecialchars() Convert special characters to HTML entities. --- implode() Returns a string by joining the elements of an array with a specified string. --- join() Alias of implode() function. --- lcfirst() Converts the first character of a string to lowercase. --- levenshtein() Calculate Levenshtein distance between two strings. --- localeconv() Returns localized numeric and monetary formatting information. --- ltrim() Removes whitespace (or other characters) from the beginning of a string. --- md5() Calculate the md5 hash of a string. --- md5\_file() Calculates the md5 hash of a file. --- metaphone() Calculate the metaphone key of a string. --- nl\_langinfo() Returns specific local information. --- nl2br() Inserts HTML line breaks before all newlines in a string. --- number\_format() Format a number with grouped thousands. --- ord() Returns the ASCII value of the first character of a string. --- parse\_str() Parses the string into variables. --- print() Outputs a string. --- printf() Outputs a formatted string. --- quoted\_printable\_decode() Convert a quoted-printable string to an 8 bit string. --- quoted\_printable\_encode() Convert a 8 bit string to a quoted-printable string. --- quotemeta() Quotes meta characters. --- rtrim() Removes whitespace (or other characters) from the end of a string. --- setlocale() Set locale information. --- sha1() Calculate the sha1 hash of a string. --- sha1\_file() Calculate the sha1 hash of a file. --- similar\_text() Calculate the similarity between two strings. --- soundex() Calculate the soundex key of a string. --- sprintf() Returns a formatted string. --- sscanf() Parses input from a string according to a format. --- str\_getcsv() Parse a CSV string into an array. --- str\_ireplace() Replace all occurrences of the search string with the replacement string. Case-insensitive version of str\_replace(). --- str\_pad() Pad a string to a certain length with another string. --- str\_repeat() Repeats a string a specified number of times. --- str\_replace() Replace all occurrences of the search string with the replacement string (case-sensitive). --- str\_rot13() Performs the ROT13 encoding on a string. --- str\_shuffle() Randomly shuffles all characters in a string. --- str\_split() Splits a string into an array. --- str\_word\_count() Counts the number of words in a string. --- strcasecmp() Binary safe comparison of two string (case-insensitive). --- strchr() Finds the first occurrence of a string inside another string. Alias of strstr() function. --- strcmp() Binary safe comparison of two string (case sensitive). --- strcoll() Locale based comparison of two string (case sensitive). --- strcspn() Returns the number of characters found in a string before any part of some specified characters are found. --- strip\_tags() Strip HTML and PHP tags from a string. --- stripcslashes() Un-quotes a string quoted with addcslashes() --- stripos() Finds the position of the first occurrence of a case-insensitive substring in a string. --- stripslashes() Un-quotes a quoted string. --- stristr() Finds the first occurrence of a string inside another string (case-insensitive). Case-insensitive version of strstr() --- strlen() Returns the length of a string. --- strnatcasecmp() Compares two strings using a “natural order” algorithm (case-insensitive). --- strnatcmp() Compares two strings using a “natural order” algorithm (case-sensitive). --- strncasecmp() Binary safe string comparison of the first n characters (case-insensitive). --- strncmp() Binary safe string comparison of the first n characters (case-sensitive). --- strpbrk() Searches a string for any of a set of characters. --- strpos() Finds the position of the first occurrence of a substring in a string. --- strrchr() Finds the last occurrence of a character in a string. --- strrev() Reverses a string. --- strripos() Finds the position of the last occurrence of a string inside another string (case-insensitive). --- strrpos() Finds the position of the last occurrence of a string inside another string (case-sensitive). --- strspn() Returns the number of characters found in a string that contains only characters from a specified charlist. --- strstr() Finds the first occurrence of a string inside another string (case-sensitive). --- strtok() Splits a string into smaller strings. --- strtolower() Converts a string to lowercase. --- strtoupper() Converts a string to uppercase. --- strtr() Translate characters or replace substrings. --- substr() Returns a part of a string. --- substr\_compare() Compares of two strings from a specified start position up to the length of the comparison. The comparison is binary safe and optionally case-sensitive. --- substr\_count() Counts the number of times a substring occurs in a string. --- substr\_replace() Replaces a part of a string with another string. --- trim() Removes whitespace (or other characters) from the beginning and end of a string. --- ucfirst() Converts the first character of a string to uppercase. --- ucwords() Converts the first character of each word in a string to uppercase. --- vfprintf() Write a formatted string to a specified output stream. --- vprintf() Outputs a formatted string. --- vsprintf() Returns a formatted string. --- wordwrap() Wraps a string to a given number of characters. Last modification:September 15, 2024 © Allow specification reprint Like 1 如果觉得我的文章对你有用,请随意赞赏