stristr() function in PHP

WBOY
Release: 2023-09-10 22:10:02
forward
1717 people have browsed it

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)
Copy after login

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;;
}
?>
Copy after login

Output

Tim is not in the string!
Copy after login

Example

The following is an example -

Live demonstration

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

Output

Demo
Copy after login

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

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!