Write a PHP script to:
- Find the length of string.
- Count number of words in a string
- Reverse of a string
- Search for a specific string
Write a PHP script to find the length of string.
Source CodeLenOfStr.php
<?php
$string = "Hello how are you?";
echo("Length of string is: ".strlen($string));
?>
Sample Output$string = "Hello how are you?";
echo("Length of string is: ".strlen($string));
?>
Length of string is: 18
Write a PHP script to count number of words in a string.
NumOfWords.php
<?php
$string = "Hello how are you?";
echo("Number of words in a string is ".str_word_count($string));
?>
Sample Output$string = "Hello how are you?";
echo("Number of words in a string is ".str_word_count($string));
?>
Number of words in a string is 4
Write a PHP script to reverse of a string.
RevStr.php
<?php
$string = "Hello how are you?";
echo("Reverse of string is: ".strrev($string));
?>
Sample Output$string = "Hello how are you?";
echo("Reverse of string is: ".strrev($string));
?>
Reverse of string is: ?uoy era woh olleH
Write a PHP script to search for a specific string.
SearchString.php
<?php
$string = "Hello how are you?";
$substring = "who";
if(strstr($string,$substring)){
echo("Substring is found.");
}else{
echo("Substring is not found.");
}
?>
Sample Output$string = "Hello how are you?";
$substring = "who";
if(strstr($string,$substring)){
echo("Substring is found.");
}else{
echo("Substring is not found.");
}
?>
Substring is not found.