public function replaceBetween($haystack, $needle, Closure $replacementMethod)
{
$parts = explode($needle, $haystack);
$sumOfParts = $parts[0];
foreach ($parts as $index => $part) {
if ($index === 0) {
continue;
}
if ($count = $this->escaped($parts[$index - 1])) {
$sumOfParts = substr($sumOfParts, 0, $count * -1) . $needle . $part;
continue;
}
$start = strpos($part, $this->opentag($part));
$end = strpos($part, $this->closetag($part));
$between = substr($part, $start + 1, $end - $start - 1);
$between = $replacementMethod($between);
$sumOfParts .= substr_replace($part, $between, 0, $end + 1);
}
return $sumOfParts;
}