Open In App

PHP String Functions Complete Reference

Last Updated : 22 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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




<?php
// 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);
?>


Output:

Without %u: 2335835140
With %u: 2335835140

The complete list of String Functions are given below:

PHP String Functions 

Description

Example

addcslashes() Add backslashes before some specified characters in a given string.
Try

addslashes() Returns a string with backslashes in front of predefined characters.
Try

bin2hex() The conversion is done byte-wise with the high-nibble first.
Try

chop() Remove white spaces or any other specified characters from the end of a string.
Try

chr() Convert a ASCII value to a character. 
Try

chunk_split() Split a string into smaller chunks of a specific length.
Try

convert_uudecode() Decode a uuencoded string encoded using convert_uuencode() function.
Try

convert_uuencode()  Encodes a string using the uuencode algorithm.
Try

count_chars() Perform several operations related to string like the number of an ASCII character occurs in a string.
Try

crc32()  This function can be used to validate data integrity.
Try

PHP crypt() Returns a hashed string using DES, Blowfish, or MD5 algorithms.
Try

password_hash()  Returns the hashed string on success or FALSE
Try

echo Display the output of parameters that are passed to it. 
Try

explode() Explode() function splits a string based on a string delimiter
Try

hex2bin() Decode a hexadecimally encoded binary string. 
Try

implode() Elements of an array. implode() is an alias for PHP
Try

join() Join an array of elements that are separated by a string.
Try

lcfirst() It takes a string as an argument 
Try

levenshtein() Calculate the levenshtein distance between two strings
Try

ltrim() Removes whitespaces or other characters
Try

md5_file() Generate the md5 hash value of a given file.
Try

md5() This function can take up to a maximum of two parameters 
Try

metaphone() Calculate the metaphone key of a given string. 
Try

nl2br() Insert HTML break tags in the place of all new lines in a string.
Try

number_format() Format a number with grouped thousands.
Try

ord() Returns the ASCII value of the first character of a string
Try

parse_str() parse_str() function is a built-in function in PHP which parses a query string into variables. 
Try

quoted_printable_decode() Decode a quoted printable string in PHP into an 8-bit string.
Try

quoted_printable_encode() Convert an 8-bit string to a quoted printable string.
Try

quotemeta() Accepts a string as an argument and returns a string 
Try

rtrim()  Removes whitespaces or other characters (if specified) from the right side of a string.
Try

sha1_file() Returns a string on success and returns FALSE otherwise.
Try

sha1()  This function an take up to a maximum of two parameters
Try

similar_text()  Returns the number of matching characters in the two strings.
Try

soundex() Calculate the Soundex key of a given string.
Try

str_pad() Pad a string to a given length.
Try

str_repeat() Create a new string by repeating a given string fixed number of times.
Try

str_replace() Replace all the occurrences of the search string or array of search strings 
Try

str_rot13()  Accepts a string and shifts every alphabet present in the string by 13 places in the alphabet
Try

str_shuffle() Randomly shuffle all the characters of a string passed to the function as a parameter.
Try

str_split() Convert the given string into an array.
Try

str_word_count() String like total number word in the string, positions of the words in the string etc. 
Try

strcasecmp() This is used to compare two given strings.
Try

strchr() Search for the first occurrence of a given string
Try

strcmp() It is used to compare two strings
Try

strcoll() It is used to compare two strings. 
Try

strcspn() Returns the number of characters present in a string 
Try

strip_tags() This is used to strips a string from HTML, and PHP tags.
Try

stripos() Find the position of the first occurrence of a string in another string.
Try

stripslashes() Removes backslashes in a string.
Try

stristr() It searches for the first occurrence of a string inside another string and displays the portion
Try

strlen() It takes a string as a parameter and returns its length.
Try

strnatcasecmp() This function is similar to strnatcmp()only difference being the (case-insensitivity).
Try

strnatcmp() Return a positive integer, negative, or zero.
Try

strncasecmp() Compare two given strings. It is case-insensitive.
Try

strncmp() Compare the first n character of two strings.
Try

strpbrk() Searches a string for any of the specified characters. 
Try

strpos()  Find the position of the first occurrence of a string in another string.
Try

strrchr() This function takes two arguments a string and a character. 
Try

strrev() It is used to reverse a string. 
Try

strripos() Out of the three parameters specified in the syntax, two are mandatory and one is optional
Try

strrpos() Out of the three parameters specified in the syntax, two are mandatory and one is optional. 
Try

strspn() Finds the length of the initial segment of a string 
Try

strstr() It searches for the first occurrence of a string inside another string and displays the portion
Try

strtok()  Tokenize a string into smaller parts on the basis of given delimiters
Try

strtolower() Convert a string into lowercase. 
Try

strtoupper() Convert a string into uppercase
Try

strtr() Replace a substring in a string to a given string of characters.
Try

substr_compare() Compare two strings from a specified start position upto a specified length.
Try

substr_count() Count the number of times a substring occurs in a given string. 
Try

substr_replace()  Replace a part of a string with another string.
Try

substr()  That is used to extract a part of a string.
Try

trim()  Removes whitespaces and also the predefined characters from both sides.
Try

ucfirst() Takes a string as an argument and returns the string
Try

ucwords() Convert the first character of every word in a string to upper-case.
Try

vprintf() Display array values as a formatted string 
Try

vsprintf() Display array values as a formatted string. 
Try

wordwrap() Wraps a given string to a given number of characters using a string break character.
Try



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads