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

stristr() function in PHP

WBOY
WBOYforward
2023-09-10 22:09:091739browse

stristr() function in PHP

stristr() function is used to search for the first occurrence of a string in another string.

Note - This function is not case sensitive

Syntax
stristr(str, search, before_search)

Parameters

  • str - The string to search for

  • search - The string to search for

  • before_search - 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

The stristr() function returns the matching substring.

Example

The following is an example-

Real-time demonstration

<?php
$mystr = &#39;Tom Hanks!&#39;;
if(stristr($mystr, &#39;Tim&#39;) === FALSE) {
   echo &#39;Tim is not in the string!&#39;;
}
?>

Output

Tim is not in the string!

Example

The following is an example -

Live demonstration

<?php
echo stristr("Demo text!","TEXT",true);
?>

Output

Demo

The above is the detailed content of stristr() 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

Related articles

See more