



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




A string is a sequence of characters, like "Hello world!".
PHP String Functions
strlen() - Return the Length of a String
The PHP strlen() function returns the length of a string.
Example
Return the length of the string "Hello world!":
str_word_count() - Count Words in a String
The PHP str_word_count() function counts the number of words in a string.
Example
Count the number of word in the string "Hello world!":
strrev() - Reverse a String
The PHP strrev() function reverses a string.
Example
Reverse the string "Hello world!":
strpos() - Search For a Text Within a String
The PHP strpos() function searches for a specific text within a string. If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE.
Example
Search for the text "world" in the string "Hello world!":
str_replace() - Replace Text Within a String
The PHP str_replace() function replaces some characters with some other characters in a string.
Example
Replace the text "world" with "Sachin":
ucfirst()
The ucfirst() function returns string converting first character into uppercase. It doesn't change the case of other characters.
Example
Output:
Php programming
lcfirst()
The lcfirst() function returns string converting first character into lowercase. It doesn't change the case of other characters.
Example
Output:
pHP Programming
ucwords()
The ucwords() function returns string converting first character of each word into uppercase.
Example
Output:
Php Programming