The string is a sequence of characters, such as "Hello world!". PHP String Functions
In this section, we will learn about commonly used string manipulation functions. PHP strlen () function
The strlen () function returns the length of a string, measured in characters.
The following example returns the length of the string "Hello world!": instance
<? PHP Echo strlen ("Hello world!" );? >
Running an instance
The output of the above code is: 12
Tip: strlen () is commonly used in loops and other functions when it is important to determine when a string ends. (for example, in a loop, we might need to stop looping after the last character of the string). PHP Strpos () function
The Strpos () function is used to retrieve the specified character or text within a string.
If a match is found, the first matching character position is returned. If no match is found, FALSE is returned.
The following example retrieves the text "World" in the string "Hello world!": instance
<? PHP Echo Strpos ("Hello world!", "World"); >
Running an instance
The output of the above code is: 6.
Tip: The position of the string "World" in the example above is 6. The reason for 6 (instead of 7) is that the position of the first character in the string is 0 instead of 1. Full PHP String Reference manual
For a complete string function reference manual, please visit our PHP String reference manual.
This manual provides a brief description and an example of each function!
"PHP Learning" PHP String functions