<?php if(isset($_POST["submit"])) { $text=$_POST['text']; echo "Word Count:"; echo str_word_count ("$text"); } ?> Run
The strrev() function is known as a string reverse function. As the name indicates reverse, the function works the same on behalf of the name. The strrev() function is used to reverse the complete string. If you enter the string "Hello" and apply strrev() function. It will convert to reverse "olleh" The following example will help you understand string reverse function.
<?php
echo strrev("Hello Learn Here")// outputs ereH nrael olleh
?>
An other example with HTML FORM (text box)
<?php
if(isset($_POST["submit"]))
{
$text=$_POST['text'];
echo "Reverse Text :";
echo strrev("$text");
}
?>
Run
The str_replace() function refers to string replace function. Str_replace() function is also readymade function of PHP.You do not need to create a function for it. The PHP str_replace() function used to replace one string to another. Let's understand with a real example. Everybody knows about notepad. The notepad is a system application. You are typing some content on a notepad. In the end, you need to replace some words. In notepad, you can replace words using find and replace function. In the PHP application, you can replace words using string replace function.
In the below example replace the string "world" with "Dolly":
<?php
echo str_replace("Learn", "Study", "Learn PHP "); // outputs Study PHP !
?>
An other example with HTML FORM (text box)
<?php
if(isset($_POST["submit"]))
{
$text=$_POST['text'];
$change =$_POST['change'];
$new=$_POST['new'];
echo "Replaced String :";
echo str_replace("$change","$new","$text");
}
?>
Run
The strpos() function is known as a string position function. It's used to find out the string position.
If you have written a paragraph and want to find out a word position within a paragraph then you can use the PHP string position function. In the below example we will search “you” in the string “How are you?
<?php
echo strpos("How are you ?", "You "); // outputs 9
?>
An other example with HTML FORM (text box)
<?php
if(isset($_POST["submit"]))
{
$text=$_POST['text'];
$search=$_POST['search'];
echo "Position:";
echo strpos("$text","$search");
}
?>
Run
The strcmp() function stands for the string compare function. It is used to compare two string. If you want to compare two string words to each other then you can use PHP readymade function strcmp(). If the strings are the same, you will get 0 ( zero) as output. The following example will help you understand strcmp() function.
<?php
if(isset($_POST["submit"]))
{
$name=$_POST['name'];
$compare=$_POST['compare'];
echo "Compared :";
echo strcmp("$name","$compare");
}
?>
Run
The strtolower() function means to convert the uppercase string to lowercase.
The strtolower() function stands for the string to lower. If you want to convert a capital word (uppercase string ) to lowercase, then you can use string to lower function. It is also a readymade string function of PHP.
>
Let's have a look at an example.
String - HELLO
Function - strtolower()
Output- hello
<?php
$str="TECHNO SMARTER";
$res=strtolower($str);//for lower case
echo $res;
?//Output techno smarter
>
An other example with HTML FORM (text box)
<?php
if(isset($_POST["submit"]))
{
$text=$_POST['text'];
echo strtolower("$text");
}
?>
Run
The Strtoupper() is opposite to string to lower function. It converts lower case string to uppercase. As the name indicates uppercase, the string to upper function is followed same.
The following example will help you to convert lowercase string to uppercase.
<?php
if(isset($_POST["submit"]))
{
$text=$_POST['text'];
echo strtoupper("$text");
}
?>
Run