PHP

php strstr函数的用法是什么

小亿
84
2024-01-02 13:56:42
栏目: 编程语言

php strstr函数是用于在字符串中查找指定的字符串,并返回从指定字符串开始到字符串末尾的部分。

函数的用法如下:

strstr(string $haystack, mixed $needle, bool $before_needle = false): string|false

参数说明:

示例:

$str = 'Hello, world!';
$part = strstr($str, 'world');
echo $part; // 输出:world!

$part2 = strstr($str, 'world', true);
echo $part2; // 输出:Hello, 

在上面的示例中,strstr($str, 'world')会找到字符串中第一次出现的 ‘world’,并返回从 ‘world’ 开始到字符串末尾的部分。而 strstr($str, 'world', true) 则会返回 ‘world’ 之前的部分。

0
看了该问题的人还看了