Find a list of place names that would be updated.

@param Tree   $tree
@param string $search
@param string $replace

@return string[]
485903
private function changePlacesUpdate(Tree $tree, string $search, string $replace): array
    {
        $individual_changes = DB::table('individuals')
            ->where('i_file', '=', $tree->id())
            ->whereContains('i_gedcom', $search)
            ->select(['individuals.*'])
            ->get()
            ->map(Individual::rowMapper());

        $family_changes = DB::table('families')
            ->where('f_file', '=', $tree->id())
            ->whereContains('f_gedcom', $search)
            ->select(['families.*'])
            ->get()
            ->map(Family::rowMapper());

        return $individual_changes
            ->merge($family_changes)
            ->mapWithKeys(static function (GedcomRecord $record) use ($search, $replace): array {
                $changes = [];

                foreach ($record->facts() as $fact) {
                    $old_place = $fact->attribute('PLAC');
                    if (preg_match('/(^|, )' . preg_quote($search, '/') . '$/i', $old_place)) {
                        $new_place           = preg_replace('/(^|, )' . preg_quote($search, '/') . '$/i', '$1' . $replace, $old_place);
                        $changes[$old_place] = $new_place;
                        $gedcom              = preg_replace('/(\n2 PLAC (?:.*, )*)' . preg_quote($search, '/') . '(\n|$)/i', '$1' . $replace . '$2', $fact->gedcom());
                        $record->updateFact($fact->id(), $gedcom, false);
                    }
                }

                return $changes;
            })
            ->sort()
            ->all();
    }
1345992
public function replace($search, $replace)
    {
        return $this->map(function ($str) use ($search, $replace) {
            return str_replace($search, $replace, $str);
        });
    }
1182027
public function replaceBeginning($search, $replacement)
    {
        return $this->regexReplace
        (
            '^'.preg_quote($search, '/'),
            UTF8::str_replace('\\', '\\\\', $replacement)
        );
    }
1033663
protected function replaceLastSequentially($search, array $replace, $subject, $encoding, &$count)
	{
		$offset = null;
		$lenSearch = mb_strlen($search, $encoding);

		foreach ($replace as $value) {
			$subject = $this->replaceLastOne($search, $value, $subject, $encoding, $count, $offset, $lenSearch);
			if($offset === false)
				break;
		}
		return $subject;
	}
1043496
public static function replaceArray($search, array $replace, $subject)
    {
        $segments = explode($search, $subject);

        $result = array_shift($segments);

        foreach ($segments as $segment) {
            $result .= (array_shift($replace) ?? $search).$segment;
        }

        return $result;
    }
43996
private function parseAdminBarTree( $tree, $root = null ) {
		$return = [];
		foreach ( $tree as $child => $parent ) {
			if ( $parent === $root ) {
				//  Remove item from tree (we don't need to traverse this again)
				unset( $tree[ $child ] );
				// Append the child into result array and parse its children
				$return[] = [
					'name' => $child,
					'children' => $this->parseAdminBarTree( $tree, $child ),
				];
			}
		}
		return empty( $return ) ? null : $return;
	}
457874
public function get($key, array $replace = [], $locale = null, $fallback = true) {
        foreach($this->bulkReplacements as $match => $extraReplace) {
            if(starts_with($key, $match)) {
                $replace = array_merge($replace, $extraReplace);
            }
        }

        return parent::get($key, $replace, $locale, $fallback);
    }
968815
public function process($value, $search, $replace)
    {
        $search = (array)$search;
        $cnt    = count($search);

        for ($i = 0; $i < $cnt; ++ $i) {
            // Credits for this to Monte Ohrt who made smarty's regex_replace modifier
            if (($pos = strpos($search[$i], "\0")) !== false) {
                $search[$i] = substr($search[$i], 0, $pos);
            }

            if (preg_match('#[a-z\s]+$#is', $search[$i], $m) && (strpos($m[0], 'e') !== false)) {
                $search[$i] = substr($search[$i], 0, - strlen($m[0])) . str_replace(array(
                        'e',
                        ' '
                    ),
                        '',
                        $m[0]);
            }
        }

        return preg_replace($search, $replace, $value);
    }
412603
public function replace($search, $replacement) {
        $regexEncoding = mb_regex_encoding();
        mb_regex_encoding($this->encoding);

        // Don't want the args being parsed as regex
        $search = preg_quote($search);
        $replacement = preg_quote($replacement);

        $str = mb_ereg_replace($search, $replacement, $this->str);
        mb_regex_encoding($regexEncoding);

        return self::create($str, $this->encoding);
    }
687011
public function places(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $search  = $request->get('search', '');
        $replace = $request->get('replace', '');

        if ($search !== '' && $replace !== '') {
            $changes = $this->changePlacesPreview($tree, $search, $replace);
        } else {
            $changes = [];
        }

        /* I18N: Renumber the records in a family tree */
        $title = I18N::translate('Update place names') . ' — ' . e($tree->title());

        return $this->viewResponse('admin/trees-places', [
            'changes' => $changes,
            'replace' => $replace,
            'search'  => $search,
            'title'   => $title,
        ]);
    }
1084483
public function replace($search, $replace): Aggregator
    {
        foreach ($this->elements as $element) {
            if ($element instanceof ReplaceableInterface) {
                $element->replace($search, $replace);
            }
        }

        return $this;
    }
1054070
protected function expandPatterns(array $patterns, $search, array $replacements)
    {
        if ($replacements === []) {
            return $patterns;
        }
        $patternsWithReplacements = [];
        foreach ($patterns as $pattern) {
            foreach ($replacements as $replacement) {
                $patternsWithReplacements[] = Files::getUnixStylePath(str_replace($search, $replacement, $pattern));
            }
        }

        return $patternsWithReplacements;
    }
1055057
public function replace($search, $replace): NamespaceDeclaration
    {
        $this->docComment->replace($search, $replace);
        $this->elements->replace($search, $replace);

        return $this;
    }
47440
public static function replace($search, $replace, $string, $caseSensitive = true)
    {
        if (!self::isValid($replace)) {
            return false;
        }

        if (!$caseSensitive) {
            return str_ireplace($search, $replace, $string);
        } else {
            return str_replace($search, $replace, $string);
        }
    }
1226384
public static function replaceLastOccurrence($search, $replace, $subject)
    {
        $pos = strrpos($subject, $search);

        if($pos !== false)
        {
            $subject = static::mb_substr_replace($subject, $replace, $pos, mb_strlen($search));
        }

        return $subject;
    }
1358765
public function replaceLast( string $search, string $replace ) : SplString
    {
        $position = strrpos( $this->__toString(), $search );

        if( $position !== false ){
            return $this->setString( substr_replace( $this->__toString(), $replace, $position, strlen( $search ) ) );
        }

        return $this;
    }
1121363
protected function replacePlaceholdersInTemplate($template, array $replace)
    {
        foreach ($replace as $placeholder => $value) {
            $template = str_replace("__{$placeholder}__", $value, $template);
        }

        return $template;
    }