Devise\Support\Str::replaceBetween PHP Method

replaceBetween() public method

Usage: replaceBetween('something @here(...) and @here(...)', '@here', function($between) { return "[ $between ]";" }); Returns something [ ... ] and [ ... ] This method is used by Devise\Pages\Docs\LiveSpan.
public replaceBetween ( string $haystack, string $needle, Closure $replacementMethod ) : string
$haystack string
$needle string
$replacementMethod Closure
return string
    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;
    }