Question

I have a for loop in php that is throwing a peculiar error.

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

Error:

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

Line 24 is the second line I showed. I know that the array $cities is populated because I checked it right before. I start with $counter equaling one because I don't want to use the first entry of the array.

What's going on here?

Était-ce utile?

La solution

It simple means that $cities[$counter] is empty string. You need to add extra check before using substr_count function.

If you have for example code:

$array = array();

$array[] = '';

array will have one element, but when you use this element in substr_count function it will raise warning

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top