String Functions
There are many string functions or methods supported for performing string operations on the data. Some methods require parameters.
Methods without Parameters
1. HTML Special Chars Decode
htmlspecialchars_decode - Convert special HTML entities to characters. This function is the opposite of htmlspecialchars().
2. HTML Special Chars
htmlspecialchars - Convert special characters to HTML entities.
3. Trim, Left Trim, Right Trim
trim - Strip whitespace from the beginning and end of a string.
ltrim - Strip whitespace from the beginning (left side) of a string.
rtrim - Strip whitespace from the end (right side) of a string.
4. Lower Case, Upper Case, Sentence Case, Capitalize Case
strtolower - Make a string lower case.
strtoupper - Make a string upper case.
ucfirst - Make a string's first character upper case (sentence case).
ucwords - Upper case the first character of each word in a string (capitalize case).
5. Length, Word Count
strlen - Get the length of the string.
str_word_count - Get the number of words in a string.
6. Reverse
strrev - Reverse a string.
7. Strip Tags
strip_tags - Strip HTML and PHP tags from a string.
8. Shuffle
str_shuffle - Randomly shuffles a string.
Methods with One Parameter
9. Repeat
str_repeat - Repeat a string
- Parameter 1: Number of time the string should be repeated. It has to be greater than or equal to 0. If it is set to 0, the function will return an empty string.
Methods with Two Parameters
10. Replace, Preg Replace
str_replace - Replace all occurrences of the search string with the replacement string.
preg_replace - Perform a regular expression search and replace.
- Parameter 1: The string or pattern to search for.
- Parameter 2: The string to replace.