This package is a helper for tags in strings
composer require rafaeldsb/php-string-tags
<?php
use RafaelDsb\Helpers\Tag;
$string = 'A string with a {{key}} and a {{tag}}';
$keys = Tag::getTags($string); // It returns ['key', 'tag']
$newString = Tag::replaceTags($string, ['key' => 'little key', 'tag' => 'door']);
echo $newString; // A string with a little key and a door
You can use it with other characters to process the tags
<?php
use RafaelDsb\Helpers\Tag;
$string = 'A string with a <key> and a <tag>';
$keys = Tag::getTags($string, '<', '>'); // It returns ['key', 'tag']
$newString = Tag::replaceTags($string, ['key' => 'little key', 'tag' => 'door'], '<', '>');
echo $newString; // A string with a little key and a door