$lt;?php if(isset($_POST["submit"])) { $text=$_POST['text']; echo "Word Count:"; echo str_word_count ("$text"); } ?> Run
The PHP strrev() function used to reverse the complete string .
<?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 PHP str_replace() function used to replaces some characters with some other characters in a string.
The example below replaces the text "world" with "Dolly":
In bellow example we will replaces the text “Learn “ with “Study”:
<?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 PHP strpos() function used for search a text(String) within a string .
If the text match within a string the fuction gives position of text that you are finding if not found match it gives FALSE
In the bellow 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 fuction strcmp() is used for compares two string .
<?php
if(isset($_POST["submit"]))
{
$name=$_POST['name'];
$compare=$_POST['compare'];
echo "Compared :";
echo strcmp("$name","$compare");
}
?>
Run
The Strtolower() is used for convert complete string to lower case .
<?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 that used for convert complete string to upper case .
<?php
if(isset($_POST["submit"]))
{
$text=$_POST['text'];
echo strtoupper("$text");
}
?>
Run