public static function replaceTokens($text, array $data) {
    $tokens = [];
    foreach ($data as $var_name => $var) {
      if (is_string($var)) {
        $tokens['{' . $var_name . '}'] = $var;
      }
    }
    return str_replace(array_keys($tokens), array_values($tokens), $text);
  }
public static function replaceTokens($text, array $data) {
    $tokens = [];
    foreach ($data as $var_name => $var) {
      if (is_string($var)) {
        $tokens['{' . $var_name . '}'] = $var;
      }
    }
    return str_replace(array_keys($tokens), array_values($tokens), $text);
  }
public static function replaceTokens ( $ text , array $ data ) { $ tokens = [ ] ; foreach ( $ data as $ var_name => $ var ) { if ( is_string ( $ var ) ) { $ tokens [ '{' . $ var_name . '}' ] = $ var ; } } return str_replace ( array_keys ( $ tokens ) , array_values ( $ tokens ) , $ text ) ; }
Replaces all tokens in a given string with appropriate values.

@param string $text
A string potentially containing replaceable tokens.
@param array $data
An array where keys are token names and values are replacements.

@return string
Text with tokens replaced.
Replaces all tokens in a given string with appropriate values .