需要帮助使用stristr

时间:2011-07-21 19:11:49

标签: php string find position

在“我能读”之后,我需要帮助返回所有内容。我知道这将搜索字符串并在数组$check中找到什么,但是如何检查然后返回“我能读”之后发现的所有内容?

$string = "I can read. I can count. I can spell.";
$check = array("I can count.", "I can't count.");
$find = stristr($string, $check, true);
echo $find;

2 个答案:

答案 0 :(得分:3)

$find = 'I can read.';
$string = '[...]';

echo substr($string,stripos($string,$find)+strlen($find));

答案 1 :(得分:1)

以下docs表示stistr的第二个参数(针):

  

如果needle不是字符串,则将其转换为整数并应用为   字符的序数值。

然后你必须定义$check如下:

$check = "I can read";

如果你想在$checkdocumentation之后获得子字符串,则不需要第三个参数:

  

如果为TRUE,stristr()会在之前返回haystack的一部分   第一次出现针。

这就是为什么你只需要用两个参数调用stristr

$find = stristr($string, $check);
相关问题