PHP strpos function for string search

You can search a character or even a string from a string through strpos function in PHP. strpos function required two string parameters first parameter is the whole string and second which you want to search. The search method returns the position value of the string which you are searching if it found in the string and if searched string does not found then it returns FALSE. The example of strpos method is mentioned below: Code


<?php
  $weekDaysString = "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday";
  $result = strpos($weekDaysString, "Tuesday");
  if($result != false){
    echo "Your string is found at position -" . $result; 
  } else {
    echo "Your string is not found.";
  }
?>
In above mentioned example we have a string variable with the name of $weekDaysString and we make a search with strpos function and try to find the 'Tuesday' string, and store the result in $result variable. We have also write a if conditional statement which shows a message that "Your string is found as position" if string found elseif string does not found then shows a message that "Your string is not found".