strstr() function in PHP

PHPProgrammingServer Side Programming

The strstr() function is used to find the first occurrence of a string.

Note − The function is case-sensitive.

Syntax

strstr(str,search,before)

Parameters

  • str − The string to search

  • search − The string to search for

  • before − A boolean value whose default is "false". If set to "true", it returns the part of the string before the first occurrence of the search parameter.

Return

The strstr() function returns the rest of string or false if the string is not found.

Example

The following is an example −

Live Demo

<?php 
   echo strstr("Brad Pitt!", "a");
?>

Output

ad Pitt!

Example

The following is an example −

Live Demo

<?php 
   echo strstr("Brad Pitt!", "a", true);
?>

Output

Br
raja
Published on 17-Oct-2018 13:06:08
Advertisements