code: public function replaceVariables($string, $replaces = [])
      {
          $callback = function ($match) use ($replaces) {
              $variable = trim($match[0], '{}');
  
              if(array_key_exists($variable, $replaces))
              {
                  return $replaces[$variable];
              }
  
              return $variable;
          };
  
          return preg_replace_callback('/{.*?}/', $callback, $string);
      }
docs: Replace variables in string with their values.
  
  @param $string
  @param array $replaces
  @return string