PHP String functions are part of the language. No installation is required to use these functions. In this reference, you will find all the useful string functions in PHP.

FunctionDescription
addcslashes()Get a string with backslashes in front of the characters
addslashes()Get a string with backslashes in front of predefined characters
bin2hex()Convert string of ASCII characters to hexadecimal values
chop()Remove whitespace or other characters from the right end of the string
chr()Returns a character from a specified ASCII value
chunk_split()Split a string into a series of smaller parts
convert_cyr_string()Convert string from one Cyrillic character-set to another
convert_uudecode()Decode a uuencoded string
convert_uuencode()Encode string using the uuencode algorithm
count_chars()Returns information about characters used in a string
crc32()Calculate a 32-bit CRC for string
crypt()One-way string hashing
echo()Output one or more strings
explode()Break string into an array
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 Hebrew text to visual text
hebrevc()Convert Hebrew text to visual text and new lines (\n) into <br>
hex2bin()Convert string of hexadecimal values to ASCII characters
html_entity_decode()Convert HTML entities to characters
htmlentities()Convert characters to HTML entities
htmlspecialchars_decode()Convert some predefined HTML entities to characters
htmlspecialchars()Convert some predefined characters to HTML entities
implode()Returns a string from the elements of an array
join()Alias of implode()
lcfirst()Convert the first character of the string to lowercase
levenshtein()Returns the Levenshtein distance between two strings
localeconv()Returns locale numeric and monetary formatting information
ltrim()Remove whitespace or other characters from the left side of the string
md5()Calculate the MD5 hash of a string
md5_file()Calculate the MD5 hash of a file
metaphone()Calculate the Metaphone key of the string
money_format()Returns a string formatted as a currency string
nl_langinfo()Returns specific local information
nl2br()Insert HTML line breaks in front of each new line in the string
number_format()Format a number with grouped thousands
ord()Get the ASCII value of the first character of the string
parse_str()Parse a query string into variables
print()Output one or more strings
printf()Output a formatted string
quoted_printable_decode()Convert a quoted-printable string to an 8-bit string
quoted_printable_encode()Convert an 8-bit string to a quoted-printable string
quotemeta()Quote meta characters
rtrim()Remove whitespace or other characters from the right side of the string
setlocale()Set locale information
sha1()Calculate the SHA-1 hash of a string
sha1_file()Calculate the SHA-1 hash of a file
similar_text()Calculate the similarity between two strings
soundex()Calculate the Soundex key of the string
sprintf()Write a formatted string to a variable
sscanf()Parse input from a string according to a format
str_getcsv()Parse a CSV string into an array
str_ireplace()Replace some characters in string (case-insensitive)
str_pad()Pad string to a new length
str_repeat()Repeat string a specified number of times
str_replace()Replace some characters in string (case-sensitive)
str_rot13()Perform the ROT13 encoding on string
str_shuffle()Randomly shuffles all characters in a string
str_split()Split string into an array
str_word_count()Count the number of words in a string
strcasecmp()Compare two strings (case-insensitive)
strchr()Finds the first occurrence of a string inside another string (alias of strstr())
strcmp()Compare two strings (case-sensitive)
strcoll()Compare two strings (locale-based string comparison)
strcspn()Get the number of characters found in the string before any part of some specified characters is found
strip_tags()Strip HTML and PHP tags from a string
stripcslashes()Unquoted string quoted with addcslashes()
stripslashes()Unquoted string quoted with addslashes()
stripos()Get the position of the first occurrence of a string inside another string (case-insensitive)
stristr()Finds the first occurrence of a string inside another string (case-insensitive)
strlen()Get the length of the string
strnatcasecmp()Compare two strings using a “natural order” algorithm (case-insensitive)
strnatcmp()Compare two strings using a “natural order” algorithm (case-sensitive)
strncasecmp()String comparison of the first n characters (case-insensitive)
strncmp()String comparison of the first n characters (case-sensitive)
strpbrk()Searche string for any of a set of characters
strpos()Get the position of the first occurrence of a string inside another string (case-sensitive)
strrchr()Find the last occurrence of a string inside another 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()Get the number of characters found in the string that contains only characters from a specified charlist
strstr()Find the first occurrence of a string inside another string (case-sensitive)
strtok()Split a string into smaller strings
strtolower()Convert string to lowercase letters
strtoupper()Convert string to uppercase letters
strtr()Translate certain characters in the string
substr()Get a part of the string
substr_compare()Compare two strings from a specified start position (binary safe and optionally case-sensitive)
substr_count()Count the number of times a substring occurs in the string
substr_replace()Replace a part of the string with another string
trim()Remove whitespace or other characters from both sides of the string
ucfirst()Convert the first character of the string to uppercase
ucwords()Convert the first character of each word in a string to uppercase
vfprintf()Write formatted string to a specified output stream
vprintf()Output formatted string
vsprintf()Write formatted string to a variable
wordwrap()Wrap string to a given number of characters
PHP String Functions