Latest web development tutorials

PHP stristr () function

PHP String Reference PHP String Reference

Examples

Find "world" in the first occurrence, and returns the remainder of the string "Hello world!":

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

Running instance »

Definition and Usage

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

Note: This function is binary safe.

Note: This function is not case-sensitive.For a case-sensitive search, use the strstr () function.


grammar

stristr( string,search,before_search )

参数 描述
string 必需。规定被搜索的字符串。
search 必需。规定所搜索的字符串。如果该参数是数字,则搜索匹配该数字对应的 ASCII 值的字符。
before_search 可选。一个默认值为 "false" 的布尔值。如果设置为 "true",它将返回 search 参数第一次出现之前的字符串部分。

technical details

return value: The remaining portion of the returned string (from the matching point). If the search string is not found, it returns FALSE.
PHP version: 4+
Update log: In PHP 5.3, add the before_search parameters.

In PHP 4.3, the function becomes binary safe.


More examples

Example 1

Through the "o" in the ASCII value of the search string, and returns the remainder of the string:

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

Running instance »

Example 2

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

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

Running instance »


PHP String Reference PHP String Reference