PHP 中的 stristr() 函数

phpprogrammingserver side programming更新于 2025/9/18 13:07:17

stristr() 函数用于搜索一个字符串在另一个字符串中首次出现的位置。

注意 − 该函数不区分大小写

语法

stristr(str, search, before_search)

参数

  • str − 需要搜索的字符串

  • search − 需要搜索的字符串

  • before_search − 布尔值,默认值为 "false"。如果设置为"true",则返回搜索参数第一次出现之前的字符串部分。

返回

stristr() 函数返回匹配的子字符串。

示例

下面是一个例子 −

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

输出

Tim is not in the string!

示例

下面是一个例子 −

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

输出

Demo

相关文章