Question: I want to make an email template and how to replace everything in the brackets `{}`and with the brackets`{}`?

```
$template = "My name is {NAME}. I'm {AGE} years old.";
$template = preg_replace("{NAME}", "Tom", $template);
$template = preg_replace("{AGE}", "10", $template);

```

and after that should look like this:
**My name is Tom. I'm 10 years old.**

Answer: 
Use `str_replace` instead of `preg_replace`:

```
$template = "My name is {NAME}. I'm {AGE} years old.";
$template = str_replace("{NAME}", "Tom", $template);
$template = str_replace("{AGE}", "10", $template);

```
`preg_replace` is not the right function to use in this situation. In this case, the correct option would be `str_replace` or `str_ireplace`. However, for a large amount of data to format, using regex would be a better idea:

```
$associative_formatter_array = array('NAME' => 'Tom', "AGE" => '10');
$template = "My name is {NAME}. I'm {AGE} years old.";
$template = preg_replace_callback("`\{([^\}]*)\}`g", function($match) {
  return $_GLOBALS["associative_formatter_array"][$match[1]];
});

```