PHP String Functions
In this tutorial, you will learn about PHP string functions used for string manipulation.
PHP offers many built-in functions for string manipulation.
| Function | Description |
|---|---|
| addcslashes() | Returns a string with backslashes before the specified characters in a given string. |
| addslashes() | Returns a string with predefined characters preceded by a backslash. |
| bin2hex() | Converts a string of ASCII characters to a hexadecimal value. |
| chop() | Removes spaces or other predefined characters from the right end of a string. |
| chr() | Returns a character from the specified ASCII value. |
| chunk_split() | Splits a string into smaller sections and inserts a specific delimiter between each section. |
| convert_uudecode() | Is used to decodes a uuencoded string. |
| convert_uudecode() | Is used to uuencode a string. |
| count_chars() | Returns information about the occurrences of characters in a string. |
| crc32() | Is used to calculate a 32-bit cyclic redundancy check (CRC) checksum of a string. |
| crypt() | Is used for one-way hashing of strings. Often used to store passwords securely. |
| echo() | Use the echo function to output data. |
| explode() | Split a string into an array of substrings based on a specified separator. |
| fprintf() | It writes a formatted string to the specified output stream. |
| get_html_translation_table() | Is used to return the conversion table used by htmlspecialchars() and htmlentities(). |
| hex2bin() | It converts a string of hexadecimal values to ASCII characters. |
| html_entity_decode() | It converts HTML entities to characters. |
| htmlentities() | It converts characters to HTML entities. |
| htmlspecialchars_decode() | It converts several predefined HTML entities to characters. |
| htmlspecialchars() | It converts some predefined characters into HTML entities. |
| implode() | Is used to returns a string consisting of the elements of the array. |
| join() | Is used to returns a string consisting of the elements of the array. |
| lcfirst() | Is used to converts the first character of a string to lowercase. |
| levenshtein() | Is used to returns the Levenshtein distance between two strings. |
| ltrim() | Is used to remove whitespaces from the beginning of a string |
| md5() | Is used to calculates the MD5 hash of a string. |
| metaphone() | Is used to calculates the metaphone key for a string. |
| nl2br() | Is used to insert HTML break tags in the place of all new lines in a string. |
| number_format() | Is used to formats numbers grouped by thousands. This function supports 1, 2, or 4 parameters (not 3). |
| ord() | Is used to return the ascii value of first character in string. |
| parse_str() | Is used to parses a query string into variables. |
| print() | Is used to print a output one or more strings. |
| printf() | Is used to print a output formatted string. |
| quoted_printable_decode() | Is used to decodes a quoted-printable string to an 8-bit ASCII string |
| quoted_printable_encode() | Is used to encodes a quoted-printable string to an 8-bit string |
| quotemeta() | Is used to add a backslashes before some predefined characters in a string. |
| rtrim() | Is used to removes whitespace or characters from the right side of a string. |
| sha1() | Is used to calculates the SHA-1 hash of a string. |
| sha1_file() | Is used to calculates the sha1_file hash of a file. |
| similar_text() | Is used to compare the similarity between two strings |
| soundex() | Is used to calculate the soundex key of a string |
| sprintf() | Is used to writes a formatted string to a variable. |
| sscanf() | Is used to return parses input from a string according to a specified format. |
| strcasecmp() | Is used to compare two given string. |
| strchr() | Is used to the search first occurrence of a given string. |
| strcmp() | Is used to compares two strings binary-safe. |
| str_ireplace() | Is used to replace some character with some other characters. |
| str_pad() | Is used to pads a string to a new length. |
| str_repeat() | Is used to repeats a string a specified number of times. |
| str_replace() | Is used to replace some character with some other characters. |
| str_rot13() | Is used to perform the ROT13 encoding on string. |
| str_shuffle() | Is used to randomly shuffles all the characters of a string. |
| str_split() | Is used to splits a string into an array. |
| str_word_count() | Is used to counts the number of words in a string. |
| strcoll() | Is used to compare two string based locale settings. |
| strcspn() | Is used to return the number of characters found in specified string. |
| strip_tags() | Is used to strips a string from HTML, XML and PHP tags. |
| stripcslashes() | Is used to removes backslashes added by the addcslashes. |
| stripslashes() | Is used to removes backslashes added by the addcslashes. |
| stripos() | Is used to find the position of the first occurrence of a string inside another string. |
| stristr() | Is used to is search for the first occurrence of a given string . |
| strlen() | Is used to is returns the length of a string. |
| strnatcasecmp() | Is used to is compare two strings using a 'natural' algorithm.. |
| strnatcmp() | Is used to is compare two strings using a 'natural' algorithm.. |
| strncasecmp() | Is used to compare two given string. |
| strncmp() | Is used to compares two strings binary-safe and case-sensitive. |
| strpbrk() | Is used to search a string for any of the set characters. |
| strpos() | Is used to find the position of the first occurrence of a string inside another string. |
| strrchr() | Is used to the search last occurrence of a given string. |
| strrev() | Is used to reverse a string. |
| strspn() | Is used to returns the number of characters found in the string only characters. |
| strstr() | Is used to find the first occurrence of the string. |
| strtok() | Is used to convert the string to smaller strings used tokenize. |
| strtolower() | Is used to convert the string to lowercase. |
| strtoupper() | Is used to convert the string to uppercase. |
| strtr() | Is used to translates certain characters in a string. |
| substr() | Is used to return a part of string. |
| substr_compare() | Is used to compares two strings from a specified start position. |
| substr_count() | Is used to compares two strings from a specified start position to specified end position. |
| substr_replace() | Is used to replaces a part of a string with another string. |
| trim() | Is used to removes whitespace and other predefined characters from right and left sides of a string. |
| ucfirst() | Is used to convert the first character of the string into the uppercase. |
| ucwords() | Is used to converts the first character of each word in a string to uppercase. |
| vprintf() | Is used to display the array values as a formatted string according to the format. |
| wordwrap() | Is used to wraps a string into new lines when it reaches a specific length. |