String Operations

Write a PHP script to:

  1. Find the length of string.
  2. Count number of words in a string
  3. Reverse of a string
  4. Search for a specific string

Write a PHP script to find the length of string.

Source Code
LenOfStr.php
<?php
  $string = "Hello how are you?";
  echo("Length of string is: ".strlen($string));
?>
Sample Output
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
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
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
Substring is not found.