warning: strpos() [function.strpos]: Empty delimiter in [path]\sites\all\modules\annotation\annotation_text\annotation_text.module on line 349.

Note: I applied the better_UI patch, but this error occurs in either case. This happens independently of content type - in any text based content that has annotation enabled.

Comments

baaj’s picture

The offending line is $pos = strpos($haystack, $needle);

  // get positions
  $pos = strpos($haystack, $needle);
  while ($pos !== FALSE) {
    $results[] = $pos;
    $pos = strpos($haystack, $needle, $pos + 1);
  }
  
  // find closest match
  if (count($results)) {
    $bestDiff = strlen($haystack) * 2; // extreme amount
    foreach ($results as $pos) {
      $diff = abs($target - $pos);
      if ($diff < $bestDiff) {
        $bestDiff = $diff;
        $bestPos = $pos;
      }
    }
  }
  
  return $bestPos; 
}
k3rr78nd’s picture

It looks like either $haystack or $needle is empty. I added one line to test for this which fixed the error for me:

 if($haystack && $needle){
  $pos = strpos($haystack, $needle);
  while ($pos !== FALSE) {
    $results[] = $pos;
    $pos = strpos($haystack, $needle, $pos + 1);
  }

  // find closest match
  if (count($results)) {
    $bestDiff = strlen($haystack) * 2; // extreme amount
    foreach ($results as $pos) {
      $diff = abs($target - $pos);
      if ($diff < $bestDiff) {
        $bestDiff = $diff;
        $bestPos = $pos;
      }
    }
  }
}

Sure there is a better way to do this but hey it's working for me so far ...
BrockBoland’s picture

Version: master » 6.x-1.x-dev
Issue summary: View changes