$values Placeholder name (without braces) to value. */ public static function fill( string $text, array $values ): string { return (string) preg_replace_callback( '/\{([a-z_]+)\}/', static fn( array $m ): string => array_key_exists( $m[1], $values ) ? (string) $values[ $m[1] ] : $m[0], $text ); } /** * Placeholder names in a text that are not in a list, e.g. typos. * * @param string $text Text with {placeholders}. * @param string[] $known Names that will be filled. * @return string[] Unknown names, in order of first use. */ public static function unknown( string $text, array $known ): array { preg_match_all( '/\{([a-z_]+)\}/', $text, $matches ); return array_values( array_unique( array_diff( $matches[1], $known ) ) ); } }