In the above program, Lessons is replaced with Programming in the string SP Lessons.
Text position in PHP strings
Description
strpos() PHP function is used to find the specific text within a string.
If the function matches then the function returns the first character position of the text in the string. If the text didn't match then the function returns false.
[php]
<!DOCTYPE html>
<html>
<body>
<?php echo strpos("SP Lessons", "Lessons"); ?>
</body>
</html>
[/php]
Output:
Count the Number of words in a string
Description
str_word_count(); PHP function is used to count the number of words in a string.
[php]
<!DOCTYPE html>
<html>
<body>
<?php echo str_word_count("Welcome to the SP Lessons"); ?>
</body>
</html>
[/php]
Output:
Summary
Key Points
String is a collection of characters.
strrev() PHP function is used to reverse the PHP strings.
strpos() PHP function is used to find the specific text within a string.