PHP String handling functions can help you to easily manipulate strings. In this article, we’ll cover some of the most commonly used string handling functions in PHP.
FUNCTION | USE |
addcslashes | Adds backslashes in front of the specified characters. |
addslashes | Adds backslashes in front of some predefined characters. |
bin2hex |
Converts binary data to
|
chop | Removes whitespace or other characters from the right end of a string. |
chr | Creates a character from a specified ASCII value. |
chunk_split | Split a string into smaller parts. |
count_chars | Returns information about characters used in a string. |
crypt | Used for one-way string hashing. |
echo | Outputs one or more strings. |
explode | Splits a string as an array. |
fprintf | Writes a formatted string to a specified output stream. |
hex2bin | Converts a hexadecimally encorded values to ASCII characters. |
html_entity_decode | Converts HTML entities to their corresponding character. |
htmlentities | Converts all characters to HTML entities. |
htmlspecialchars_decode | Convert special HTML entities back to characters. |
htmlspecialchars | Converts some predefined characters to HTML entities. |
implode | Creates a string from array elements. |
join | Alias of implode function. |
lcfirst | Makes the first character of a string lowercase. |
ltrim | Removes whitespace or other characters from the beginning of a string. |
md5 | Calculates the md5 hash of a string |
nl2br | Appends HTML line breaks before all newlines in a string. |
number_format | Formats a number with grouped thousands. |
Outputs a string. | |
printf | Outputs a formatted string. |
rtrim | Removes whitespace or other characters from the end of a string. |
sha1 | Calculate the sha1 hash of a string. |
similar_text | Calculates the similarity between two strings. |
sprintf | Returns a formatted string. |
sscanf | Creates input from a string according to a format. |
str_getcsv | Converts a CSV string as an array. |
str_ireplace | Replaces some characters in a string. It is the case-insensitive version of str_replace. |
str_pad | Pads a string to a new length. |
str_repeat | Repeats a string for a specified number of times. |
str_replace | Replaces all the occurrences of a string. It is case-sensitive. |
str_shuffle | Shuffles all characters of a string. |
str_split | Splits a string into an array. |
str_word_count | Counts the number of words in a string. |
strcasecmp | Performs a case-insensitive string comparison. |
strcmp | Performs a case-sensitive string comparison. |
strip_tags | Removes HTML and PHP tags from a string |
stripcslashes | Un-quote string quoted with addcslashes function. |
stripos | Finds the position of the first occurrence of a case-insensitive substring in a string. |
stripslashes | Un-quotes a quoted string. |
strlen | Calculates the length of a string. |
strnatcasecmp | Performs a case-insensitive string comparison. |
strpos | Finds the position of the first occurrence of a case-sensitive substring in a string. |
strrchr | Find the last occurrence of a character in a string. |
strrev | Finds the reverse of a string. |
strripos | Finds the position of the last occurrence of a case-insensitive substring in a string. |
strrpos | Finds the position of the last occurrence of a case-sensitive substring in a string. |
strstr | Find the first occurrence of a string (Case-sensitive). |
strtolower | Converts a string to lowercase. |
strtoupper | Converts a string to uppercase . |
strtr | Translates certain characters or replace a substring from a string. |
substr_count | Finds the total numbers of occurrences of a substring. |
substr_replace | Replaces a part of a string (substring) with another. |
substr | Returns a substring. |
trim | Removes whitespace or other characters from the beginning and end of a string. |
ucfirst | Make the first character of a string uppercase. |
ucwords | Make the first character of each word in a string uppercase. |
wordwrap | Wraps a string to a given number of characters. |
This article does not explain about all PHP string handling functions.
Subscribe
Join the newsletter to get the latest updates.