[英]php - How do I get rid of this strange “empty delimiter” message
I have some code that uses the stristr function to extract data I need. 我有一些代码使用stristr函数来提取我需要的数据。
It gives me this Warning for every iteration of the loop: 它为循环的每次迭代提供了这个警告:
Warning: stristr() [function.stristr]: Empty delimiter in ... line 55
The code works apart from this Warning. 代码与此警告不同。 Here is the code:
这是代码:
$data = stristr("$text", "$key");
$result = string_limit_words($data,2);
print "$result<BR>";
How do I get rid of the warning message? 如何摆脱警告信息?
$data = $text;
if($key)
$data = stristr($data, $key);
$result = string_limit_words($data,2);
print "$result<BR>";
Basically only do the stristr if the $key (the needle) is not an empty string 基本上只有当$ key(针)不是空字符串时才执行stristr
Quote from php.net stristr user: dpatton.at.confluence.org 引自php.net stristr用户:dpatton.at.confluence.org
There was a change in PHP 4.2.3 that can cause a warning message to be generated when using stristr(), even though no message was generated in older versions of PHP. PHP 4.2.3中的更改可能导致在使用stristr()时生成警告消息,即使在旧版本的PHP中没有生成消息。
The following will generate a warning message in 4.0.6 and 4.2.3: 以下将在4.0.6和4.2.3中生成警告消息:
stristr("haystack", "");
OR 要么
$needle = "";
stristr("haystack", $needle);
This will not generate an "Empty Delimiter" warning message in 4.0.6, but will in 4.2.3: 这不会在4.0.6中生成“空分隔符”警告消息,但会在4.2.3中生成:
unset($needle);
stristr("haystack", $needle);
Here's a URL that documents what was changed 这是一个记录更改内容的URL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.