【问题标题】:Empty Substring warning in PHPPHP中的空子字符串警告
【发布时间】:2014-05-13 17:59:07
【问题描述】:

我在 php 中有一个 for 循环,它抛出了一个特殊的错误。

for ($counter=1; $counter < count($cities); $counter++)
    $dataset[$cities[$counter]]=substr_count($votecontents, $cities[$counter]);

错误:

Warning: substr_count() [function.substr-count]: Empty substring in [OMITTED] on line 24

第 24 行是我展示的第二行。我知道数组 $cities 已填充,因为我之前检查过它。我从等于一个的$counter 开始,因为我不想使用数组的第一个条目。

这是怎么回事?

【问题讨论】:

    标签: php arrays substring warnings


    【解决方案1】:

    简单的意思是$cities[$counter] 是空字符串。您需要在使用 substr_count 函数之前添加额外的检查。

    如果您有示例代码:

    $array = array();
    
    $array[] = '';
    

    数组只有一个元素,但是当你在 substr_count 函数中使用这个元素时,它会引发警告

    【讨论】:

    • 哦,没关系...我自己想通了。无论如何,我会给你一些分数。
    猜你喜欢
    • 2014-06-17
    • 2013-11-15
    • 1970-01-01
    • 2013-04-11
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多