PHP stristr()Functions

PHP String 参考手册PHP String Reference

Examples

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

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

Run Example »

Definition and Usage

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

Note:The function is binary-safe.

Note:The function is case-insensitive. For case-sensitive searches, use thestrstr()function.


Syntax

stristr(string,search,before_search)

Parameter Description
string Required. Specifies the string to be searched.
search Required. Specifies the string to search for. If this parameter is a number, it searches for the character matching the ASCII value of the number.
before_search Optional. A boolean value with a default of "false". If set to "true", it returnssearchthe part of the string before the first occurrence of the parameter.

Technical Details

Return Value: Returns the rest of the string (from the match point). If the searched string is not found, returns FALSE.
PHP Version: 4+
Changelog: In PHP 5.3, thebefore_searchparameter was added.

In PHP 4.3, the function became binary-safe.


More Examples

Example 1

Search for the string using the ASCII value of "o", and return the rest of the string:

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

Run Example »

Example 2

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

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

Run Example »


PHP String 参考手册PHP String Reference Other Extensions