PHP 7 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.
Function | Description |
---|---|
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. |