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 −

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

Updated on: 30-Jul-2019

218 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements