Computer >> Computer tutorials >  >> Programming >> PHP

strstr() function in PHP


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 −

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

Output

ad Pitt!

Example

The following is an example −

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

Output

Br