Search code examples
phpwarningsstrpos

Warning: strpos() [function.strpos]: Empty delimiter in foreach statement


I have read all topics regarding strpos() issues but I cant find one that will fix mine. So here is the code.

foreach($titles_array as $k=>$v) {
if(strpos($subject,$v) !== false) {
        $i++;
    $asd[$titles['id']] = $i;   
}
}

The script works good and I get the results I'm looking for but this error comes up : Warning: strpos() [function.strpos]: Empty delimiter

I read that it might be an empty string or value in array but I've checked them both and I didnt found any empty string/value. I appreciate any help. All the best !


Solution

  • The "empty delimiter" warning occurs when the second parameter to strpos is empty. You definitely have an empty value in $titles_array.

    I have reproduced the warning here: http://3v4l.org/RnU3q

    Try print_r($titles_array) right before your foreach loop.