A string is a sequence of characters which gives definite or indefinite meaning.
String functions are used to manipulate strings inside the program.
Some of the string functions are :
- strlen()
- str_word_count()
- strrev()
- strpos()
- str_replace() etc.
Strlen() :
The PHP strlen() function returns the length of a string.
Example :
<!DOCTYPE html>
<html>
<body>
<?php
echo strlen("Hello LetsUpgrade peeps!");
?>
</body>
</html>
Output : it will show as 24 as the total number of words in it is 24.
str_word_count() :
The PHP str_word_count() function counts the number of words in a string.
Example :
<!DOCTYPE html>
<html>
<body>
<?php
echo str_word_count("Hello world!");
?>
</body>
</html>
Output : it will show as 2 as the word count is 2 - hello & world
strrev() :
The PHP strrev() function reverses a string.
Example :
<!DOCTYPE html>
<html>
<body>
<?php
echo strrev("olleH edargpUsteL!");
?>
</body>
</html>
Output :

strpos() :
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 :
<!DOCTYPE html>
<html>
<body>
<?php
echo strpos("Hello world!", "world");
?>
</body>
</html>
Output :
It’ll return as 6 as the World - W starts at place 6 ----.
Note : The first character position in a string is always 0 (not 1).
Str_replace() :
The PHP str_replace() function replaces some characters with some other characters in a string.
Example :
<!DOCTYPE html>
<html>
<body>
<?php
echo str_replace("Peoples", "Peeps", "Hello to the Peoples of LetsUpgrade, Greetings from earth!");
?>
</body>
</html>
Output :

PHP Resource :
The special resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP. A common example of using the resource data type is a database call.
We will not talk about the resource type here, since it is an advanced topic.