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. | Command | Description | Example |
---|---|---|---|
1 | addcslashes() | This will return the escaped string before the specified characters in list. | addcslashes example |
2 | addslashes() | This will add/suffix backslash(\) in front of each predefined characters for e.g. single quote(‘) and double quote(“) in string. | addslashes Example |
3 | bin2hex() | Converts a string of ASCII characters to hexadecimal values. | Click Here |
4 | chop() | Removes whitespace or other characters from the right end of a string. | Click Here |
5 | chr() | This function returns a character from a specified ASCII value. | Click Here |
6 | chunk_split() | Splits a string into smaller chunks. | Click Here |
7 | convert_cyr_string() | This functions converts one string Cyrillic character set to another. | Click Here |
8 | convert_uudecode() | Decodes a uuencoded string by convert_uuencode() function | Click Here |
9 | convert_uuencode() | Encodes a string using the uuencode algorithm. | Click Here |
10 | count_chars() | Return information about characters used in a string | Click Here |
11 | crc32() | Cyclic redundancy checksum polynomial of 32-bit lengths of the string | Click Here |
12 | crypt() | One-way string hashing | Click Here |
13 | echo() | Outputs one or more strings. | Click Here |
14 | explode() | Breaks a string into an array. | Click Here |
15 | fprintf() | It writes a formatted string to a stream. | Click Here |
16 | get_html_translation_table() | It returns the translation table used by htmlspecialchars() and htmlentities(). | Click Here |
17 | hebrev() | Converts logical Hebrew text to visual text without newline conversion., | Click Here |
18 | hebrevc() | Converts logical Hebrew text to visual text with newline conversion. | Click here |
19 | hex2bin() | Converts a string of hexadecimal values to ASCII characters. | Click Here |
20 | html_entity_decode() | Converts HTML entities to their applicable characters. | Click Here | 21 | htmlentities() | It will converts all possible characters to HTML entities. | Click Here |
22 | htmlspecialchars_decode() | Converts some predefined HTML entities back to characters. | Click Here |
23 | htmlspecialchars() | Converts all possible characters to HTML entities. | Click Here |
24 | implode() | This will join array elements in a string. | Click Here |
25 | join() | Joins two or more strings together | Click Here | 26 | lcfirst() | It converts first letter of a string to lowercase letter. | Click Here |
27 | levenshtein() | It calculates Levenshtein distance between two strings. | Click Here |
28 | localeconv() | It will Get numeric formatting information. | Click Here |
29 | ltrim() | Truncate spaces or other characters from starting of input string. | Click Here |
30 | md5_file() | Calculates the MD5 hash of a file. | Click Here | 31 | md5() | Calculates the MD5 hash of a string. | Click Here |
32 | metaphone() | Calculate the metaphone key of a string. | Click Here |
33 | money_format() | Formats a number to a currency string. | Click Here |
34 | nl_langinfo() | Returns the locale information. | Click Here |
35 | nl2br() | Inserts HTML line breaks before all newlines in a string. | Click Here | 36 | number_format() | Format a number. | Click Here |
37 | ord() | Calculates the ASCII value of first character of a string. | Click Here |
38 | parse_str() | It parses a query string into variables. | Click Here |
39 | print() | Outputs one or more strings. | Click Here |
40 | printf() | Output a formatted string. | Click Here | 41 | quoted_printable_decode() | Decodes a quoted-printable string to an 8-bit string. | Click Here |
42 | quoted_printable_encode() | Convert a 8 bit string to a quoted-printable string. | Click Here |
43 | quotemeta() | Adds backslashes in front of some predefined characters. | Click Here |
44 | rtrim() | Truncate spaces or other characters from the end of input string. | Click Here |
45 | setlocale() | Function sets the locale information. | Click Here | 46 | sha1_file() | Calculates the sha1 hash of the file. | Click Here |
47 | sha1() | Calculates the sha1 hash of a string. | Click Here |
48 | similar_text() | Calculates the similarity between two strings | Click Here |
49 | soundex() | Calculates the soundex key of str. | Click Here |
50 | sprintf() | Function output a formatted string. | Click Here | 51 | sscanf() | Function parses input from a string according to a string_format. | Click Here |
52 | str_getcsv() | Parse a CSV string into an array | Click here |
53 | str_ireplace() | Replace all occurrences of the search string with the replacement string. It is case – insensitive function. , | Click here |
54 | str_pad() | Pad a string to a certain length with another string. | Click here |
55 | str_repeat() | Repeats a string a specified number of times. | Click here | 56 | str_replace() | Replace all occurrences of the search string with the replacement string. | Click here |
57 | str_rot13() | Perform the ROT13 transform/encoding and decoding on a string. | Click here |
58 | str_shuffle() | Shuffles a string randomly. | Click here |
59 | str_split() | Breaks a string into an array. | Click here |
60 | str_word_count() | Counts the number of words in a string. | Click here | 61 | strcasecmp() | Case-insensitive string comparison function. | Click here |
62 | strchr() | Find the first occurrence of search in a string. | Click here |
63 | strcmp() | Binary safe and case-sensitive function. | Click here |
64 | strcoll() | Compares two strings based on locale. | Click here |
65 | strcspn() | Returns the number of characters found in a string before any part of the specified characters are found. | Click here | 66 | strip_tags() | It strip HTML and PHP tags from a string. | Click here |
67 | stripcslashes() | Removes the backslashes from string | Click here |
68 | stripos() | Find the position of the first occurrence of a search_string in a string. | Click here |
69 | stripslashes() | Un-quote string quoted with addslashes(). | Click here |
70 | stristr() | Find the first occurrence of search in a string. | Click here | 71 | strlen() | It returns the length of a string. | Click here |
72 | strnatcasecmp() | Compares the two strings using a “natural” algorithm. | Click here |
73 | strnatcmp() | Compares the two strings using a “natural” algorithm. | Click here |
74 | strncasecmp() | It will compare two strings. | Click here |
75 | strncmp() | This function will compare two strings in case-sensitive mode. | Click here |
76 | strpbrk() | It will searches a string for any of the specified characters. | Click here |
77 | strpos() | It will find the position of the first occurrence of a search_string in a string. | Click here |
78 | strrchr() | This function will find the last occurrence of char_string in a string. | Click here |
79 | strrev() | This function will reverse the string. | Click here |
80 | strripos() | This function find the position of the last occurrence of a search_string in a string. | Click here |
81 | strrpos() | This function will find the position of the last occurrence of a search_string in a string. | ,Click here |
82 | strspn | Click here | |
83 | strstr() | This functions find the first occurrence of search in a string. | Click here |
84 | strtok() | Tokenize string or we can say splits a string into smaller strings (tokens). | Click here |
85 | strtolower() | Converts all letter of a string to lowercase letter. | Click here |
86 | strtoupper() | Converts all letter of a string to uppercase letter. | Click here |
87 | strtr() | It will translate characters or replace strings. | Click here |
88 | substr_compare() | It will compares two strings from a specified start position. | Click here |
89 | substr_count() | It will counts the number of times a substring comes in a string. | Click here |
90 | substr_replace() | It will replace text within a part of a string. | Click here |
91 | substr() | It will return part of a string. | Click here |
92 | trim() | This function truncate spaces or other characters from the beginning and end of input string. | Click here |
93 | ucfirst() | Converts first letter of a string to uppercase letter. | Click here |
94 | ucwords() | Converts first letter of every word in a string to uppercase letter. | Click here |
95 | vfprintf | Click here | |
96 | vprintf | Click here | |
97 | vsprintf | Click here | |
98 | wordwrap | Wraps 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