All About PHP 5 String Functions with Examples

PHP 5 String Functions: PHP continues to be the mainstay of web development with several CMS, frameworks, and platforms built around it. One of the main keys to success lies in the list of PHP built-in functions it offers for developers to expand its functionality. And here in this blog, we will get to know string functions in PHP5 with examples. This is an important list of PHP5 String Functions which is part of the fundamental PHP core. You can use these functions directly into your application without any installation of 3rd Party Services.


PHP 5 String Functions list with examples

No.CommandDescriptionExample
1addcslashes()This will return the escaped string before the specified characters in list.addcslashes example
2addslashes()This will add/suffix backslash(\) in front of each predefined characters for e.g. single quote(‘) and double quote(“) in string.addslashes Example
3bin2hex()Converts a string of ASCII characters to hexadecimal values.Click Here
4chop()Removes whitespace or other characters from the right end of a string.Click Here
5chr()This function returns a character from a specified ASCII value.Click Here
6chunk_split()Splits a string into smaller chunks.Click Here
7convert_cyr_string()This functions converts one string Cyrillic character set to another.Click Here
8convert_uudecode()Decodes a uuencoded string by convert_uuencode() functionClick Here
9convert_uuencode()Encodes a string using the uuencode algorithm.Click Here
10count_chars()Return information about characters used in a stringClick Here
11crc32()Cyclic redundancy checksum polynomial of 32-bit lengths of the stringClick Here
12crypt()One-way string hashingClick Here
13echo()Outputs one or more strings.Click Here
14explode()Breaks a string into an array.Click Here
15fprintf()It writes a formatted string to a stream.Click Here
16get_​html_​translation_​table()It returns the translation table used by htmlspecialchars() and htmlentities().Click Here
17hebrev()Converts logical Hebrew text to visual text without newline conversion.,Click Here
18hebrevc()Converts logical Hebrew text to visual text with newline conversion.Click here
19hex2bin()Converts a string of hexadecimal values to ASCII characters.Click Here
20html_entity_decode()Converts HTML entities to their applicable characters.Click Here
21htmlentities()It will converts all possible characters to HTML entities.Click Here
22htmlspecialchars_decode()Converts some predefined HTML entities back to characters.Click Here
23htmlspecialchars()Converts all possible characters to HTML entities.Click Here
24implode()This will join array elements in a string.Click Here
25join()Joins two or more strings togetherClick Here
26lcfirst()It converts first letter of a string to lowercase letter.Click Here
27levenshtein()It calculates Levenshtein distance between two strings.Click Here
28localeconv()It will Get numeric formatting information.Click Here
29ltrim()Truncate spaces or other characters from starting of input string.Click Here
30md5_​file()Calculates the MD5 hash of a file.Click Here
31md5()Calculates the MD5 hash of a string.Click Here
32metaphone()Calculate the metaphone key of a string.Click Here
33money_​format()Formats a number to a currency string.Click Here
34nl_​langinfo()Returns the locale information.Click Here
35nl2br()Inserts HTML line breaks before all newlines in a string.Click Here
36number_format()Format a number.Click Here
37ord()Calculates the ASCII value of first character of a string.Click Here
38parse_​str()It parses a query string into variables.Click Here
39print()Outputs one or more strings.Click Here
40printf()Output a formatted string.Click Here
41quoted_​printable_​decode()Decodes a quoted-printable string to an 8-bit string.Click Here
42quoted_​printable_​encode()Convert a 8 bit string to a quoted-printable string.Click Here
43quotemeta()Adds backslashes in front of some predefined characters.Click Here
44rtrim()Truncate spaces or other characters from the end of input string.Click Here
45setlocale()Function sets the locale information.Click Here
46sha1_​file()Calculates the sha1 hash of the file.Click Here
47sha1()Calculates the sha1 hash of a string.Click Here
48similar_​text()Calculates the similarity between two stringsClick Here
49soundex()Calculates the soundex key of str.Click Here
50sprintf()Function output a formatted string.Click Here
51sscanf()Function parses input from a string according to a string_format.Click Here
52str_getcsv()Parse a CSV string into an arrayClick here
53str_ireplace()Replace all occurrences of the search string with the replacement string. It is case – insensitive function. ,Click here
54str_pad()Pad a string to a certain length with another string.Click here
55str_repeat()Repeats a string a specified number of times.Click here
56str_replace()Replace all occurrences of the search string with the replacement string.Click here
57str_rot13()Perform the ROT13 transform/encoding and decoding on a string.Click here
58str_shuffle()Shuffles a string randomly.Click here
59str_split()Breaks a string into an array.Click here
60str_word_count()Counts the number of words in a string.Click here
61strcasecmp()Case-insensitive string comparison function.Click here
62strchr()Find the first occurrence of search in a string.Click here
63strcmp()Binary safe and case-sensitive function.Click here
64strcoll()Compares two strings based on locale.Click here
65strcspn()Returns the number of characters found in a string before any part of the specified characters are found.Click here
66strip_tags()It strip HTML and PHP tags from a string.Click here
67stripcslashes()Removes the backslashes from stringClick here
68stripos()Find the position of the first occurrence of a search_string in a string.Click here
69stripslashes()Un-quote string quoted with addslashes().Click here
70stristr()Find the first occurrence of search in a string.Click here
71strlen()It returns the length of a string.Click here
72strnatcasecmp()Compares the two strings  using a “natural” algorithm.Click here
73strnatcmp()Compares the two strings  using a “natural” algorithm.Click here
74strncasecmp()It will compare two strings.Click here
75strncmp()This function will compare two strings in case-sensitive mode.Click here
76strpbrk()It will  searches a string for any of the specified characters.

Click here
77strpos()It will find the position of the first occurrence of a search_string in a string.Click here
78strrchr()This function will find the last occurrence of char_string in a string.Click here
79strrev()This function will reverse the string.Click here
80strripos()This function find the position of the last occurrence of a search_string in a string.Click here
81strrpos()This function will find the position of the last occurrence of a search_string in a string. ,Click here
82strspnClick here
83strstr()This functions find the first occurrence of search in a string.Click here
84strtok()Tokenize string or we can say splits a string into smaller strings (tokens).

Click here
85strtolower()Converts all letter of a string to lowercase letter.Click here
86strtoupper()Converts all letter of a string to uppercase letter.Click here
87strtr()It will translate characters or replace strings.Click here
88substr_​compare()It will compares two strings from a specified start position.Click here
89substr_​count()It will counts the number of times a substring comes in a string.Click here
90substr_​replace()It will replace text within a part of a string.Click here
91substr()It will return part of a string.Click here
92trim()This function truncate spaces or other characters from the beginning and end of input string.Click here
93ucfirst()Converts first letter of a string to uppercase letter.Click here
94ucwords()Converts first letter of every word in a string to uppercase letter.Click here
95vfprintfClick here
96vprintfClick here
97vsprintfClick here
98wordwrapWraps a string to a given number of width using a string break character.Click here
99
100

More References

PHP Official Website
W3 School PHP String function


Also read PHP Interview Question and Answers for Freshers in detail.


Must Read in PHP

>>How to Convert String to Number in PHP



You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *