$vars Values keyed by tag name. * @return string */ public static function apply( string $text, array $vars ): string { return (string) preg_replace_callback( '/\{([a-z0-9_]+)\}/', static function ( array $found ) use ( $vars ) { return isset( $vars[ $found[1] ] ) && is_scalar( $vars[ $found[1] ] ) ? (string) $vars[ $found[1] ] : ''; }, $text ); } /** * Tags used in a text. * * @since 0.1.0 * * @param string $text Text. * @return string[] Tag names without braces, each once. */ public static function used( string $text ): array { preg_match_all( '/\{([a-z0-9_]+)\}/', $text, $matches ); return array_values( array_unique( $matches[1] ) ); } }