Skip to content
Related Articles
Open in App
Not now

Related Articles

PHP String Functions Complete Reference

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 24 Jan, 2023
Improve Article
Save Article

Strings are a collection of characters. For example, ‘G’ is the character and ‘GeeksforGeeks’ is the string. Installation: These functions are not required any installation. These are the part of PHP core. The complete list of PHP string functions are given below:


Example: This program helps us to calculate a 32-bit CRC for the string “Hello World”, both with %u and without %u.


// PHP program illustrate the
// crc32() function
$str1 = crc32("Hello world.");
// print without %u
echo 'Without %u: '.$str1."\n";
// print with %u
echo 'With %u: ';
printf("%u\n", $str1);


Without %u: 2335835140
With %u: 2335835140

The complete list of String Functions are given below:

PHP String Functions 


addcslashes()Add backslashes before some specified characters in a given string.
addslashes()Returns a string with backslashes in front of predefined characters.
bin2hex()The conversion is done byte-wise with the high-nibble first.
chop()Remove white spaces or any other specified characters from the end of a string.
chr()Convert a ASCII value to a character. 
chunk_split()Split a string into smaller chunks of a specific length.
convert_uudecode()Decode a uuencoded string encoded using convert_uuencode() function.
convert_uuencode() Encodes a string using the uuencode algorithm.
count_chars()Perform several operations related to string like the number of an ASCII character occurs in a string.
crc32() This function can be used to validate data integrity.
PHP crypt()Returns a hashed string using DES, Blowfish, or MD5 algorithms.
password_hash() Returns the hashed string on success or FALSE
echoDisplay the output of parameters that are passed to it. 
explode()Explode() function splits a string based on a string delimiter
hex2bin()Decode a hexadecimally encoded binary string. 
implode()Elements of an array. implode() is an alias for PHP
join()Join an array of elements that are separated by a string.
lcfirst()It takes a string as an argument 
levenshtein()Calculate the levenshtein distance between two strings
ltrim()Removes whitespaces or other characters
md5_file()Generate the md5 hash value of a given file.
md5()This function can take up to a maximum of two parameters 
metaphone()Calculate the metaphone key of a given string. 
nl2br()Insert HTML break tags in the place of all new lines 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()parse_str() function is a built-in function in PHP which parses a query string into variables. 
quoted_printable_decode()Decode a quoted printable string in PHP into an 8-bit string.
quoted_printable_encode()Convert an 8-bit string to a quoted printable string.
quotemeta()Accepts a string as an argument and returns a string 
rtrim() Removes whitespaces or other characters (if specified) from the right side of a string.
sha1_file()Returns a string on success and returns FALSE otherwise.
sha1() This function an take up to a maximum of two parameters
similar_text() Returns the number of matching characters in the two strings.
soundex()Calculate the Soundex key of a given string.
str_pad()Pad a string to a given length.
str_repeat()Create a new string by repeating a given string fixed number of times.
str_replace()Replace all the occurrences of the search string or array of search strings 
str_rot13() Accepts a string and shifts every alphabet present in the string by 13 places in the alphabet
str_shuffle()Randomly shuffle all the characters of a string passed to the function as a parameter.
str_split()Convert the given string into an array.
str_word_count()String like total number word in the string, positions of the words in the string etc. 
strcasecmp()This is used to compare two given strings.
strchr()Search for the first occurrence of a given string
strcmp()It is used to compare two strings
strcoll()It is used to compare two strings. 
strcspn()Returns the number of characters present in a string 
strip_tags()This is used to strips a string from HTML, and PHP tags.
stripos()Find the position of the first occurrence of a string in another string.
stripslashes()Removes backslashes in a string.
stristr()It searches for the first occurrence of a string inside another string and displays the portion
strlen()It takes a string as a parameter and returns its length.
strnatcasecmp()This function is similar to strnatcmp()only difference being the (case-insensitivity).
strnatcmp()Return a positive integer, negative, or zero.
strncasecmp()Compare two given strings. It is case-insensitive.
strncmp()Compare the first n character of two strings.
strpbrk()Searches a string for any of the specified characters. 
strpos() Find the position of the first occurrence of a string in another string.
strrchr()This function takes two arguments a string and a character. 
strrev()It is used to reverse a string. 
strripos()Out of the three parameters specified in the syntax, two are mandatory and one is optional
strrpos()Out of the three parameters specified in the syntax, two are mandatory and one is optional. 
strspn()Finds the length of the initial segment of a string 
strstr()It searches for the first occurrence of a string inside another string and displays the portion
strtok() Tokenize a string into smaller parts on the basis of given delimiters
strtolower()Convert a string into lowercase. 
strtoupper()Convert a string into uppercase
strtr()Replace a substring in a string to a given string of characters.
substr_compare()Compare two strings from a specified start position upto a specified length.
substr_count()Count the number of times a substring occurs in a given string. 
substr_replace() Replace a part of a string with another string.
substr() That is used to extract a part of a string.
trim() Removes whitespaces and also the predefined characters from both sides.
ucfirst()Takes a string as an argument and returns the string
ucwords()Convert the first character of every word in a string to upper-case.
vprintf()Display array values as a formatted string 
vsprintf()Display array values as a formatted string. 
wordwrap()Wraps a given string to a given number of characters using a string break character.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!