PHP stristr() Function

Example

Find the first occurrence of "world" in "Hello world!" and return the remaining part of the string:

<?php
echo stristr("Hello world!","WORLD");
?>

Run Examples

Definition and Usage

The stristr() function searches for the first occurrence of a string within another string.

Note:This function is binary safe.

Note:This function is case-insensitive. If you need to perform a case-sensitive search, please use strstr() Function.

Syntax

stristr(string,search
,before_search)
Parameters Description
string Required. Specifies the string to be searched in.
search

Required. Specifies the string to be searched.

If this parameter is a number, it will search for the character corresponding to the ASCII value of the number.

before_search

Optional. The default value is "false" boolean.

If set to "true", it will return search The string part before the first occurrence of the parameter.

Technical Details

Return Value: Return the remaining part of the string (from the match point). If the searched string is not found, FALSE is returned.
PHP Version: 4+
Update Log:

In PHP 5.3, a new parameter was added: before_search Parameters.

In PHP 4.3, this function becomes binary safe.

More Examples

Example 1

Search for the string with the ASCII value of "o" and return the remaining part of the string:

<?php
echo stristr("Hello world!",111);
?>

Run Examples

Example 2

Return the string part before the first occurrence of "world":

<?php
echo stristr("Hello world!","WORLD",true);
?>

Run Examples