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
<?phpecho 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
<?phpecho 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.
PHP String Functions