php stristr函数的用法是什么

php stristr函数的用法是什么

技术问答

stristr函数是PHP中用来查找字符串中第一次出现的子字符串(不区分大小写)的函数。其语法为:

stristr(string $haystack , string $needle , bool $before_needle = false): ?string

参数说明:

  • $haystack:要查找的字符串
  • $needle:要查找的子字符串
  • $before_needle:可选参数,设置为true将返回子字符串之前的部分,否则返回子字符串及其后的部分

示例:

$string = 'Hello, World!';
$substring = 'world';

$result = stristr($string, $substring);

echo $result; // 输出: World!

在上面的示例中,由于stristr函数对大小写不敏感,所以即使$substring的大小写与实际字符串不一致,仍然能够找到对应的子字符串。

本文地址:https://www.sztg.com.cn/article/56210.html

如非特殊说明,本站内容均来自于网友自主分享,如有任何问题均请联系我们进行处理!

猜您喜欢