php - 如何摆脱这个奇怪的"空分隔符"消息

Ste*_*ven 7 php

我有一些代码使用stristr函数来提取我需要的数据.

它为循环的每次迭代提供了这个警告:

Warning: stristr() [function.stristr]: Empty delimiter in ... line 55
Run Code Online (Sandbox Code Playgroud)

代码与此警告不同.这是代码:

$data = stristr("$text", "$key");
$result = string_limit_words($data,2);
print "$result<BR>";
Run Code Online (Sandbox Code Playgroud)

如何摆脱警告信息?

Bob*_*mer 6

$data = $text;
if($key)
   $data = stristr($data, $key);
$result = string_limit_words($data,2);
print "$result<BR>";
Run Code Online (Sandbox Code Playgroud)

基本上只有当$ key(针)不是空字符串时才执行stristr