Home  >  Article  >  Backend Development  >  strstr() function in PHP

strstr() function in PHP

王林
王林forward
2023-09-08 11:53:081618browse

strstr() function in PHP

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

Note - This function is case-sensitive.

grammar

strstr(str,search,before)

parameter

  • str - The string to search for

  • search - The string to search for

  • before - A boolean value, default value is "false". If set to "true", returns the portion of the string preceding the first occurrence of the search parameter.

return

strstr() function returns the rest of the 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

The above is the detailed content of strstr() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete