You are here

function token_custom_eval in Custom Tokens 7

Evaluate a string of PHP code. (Copy from drupal_eval())

This is a wrapper around PHP's eval(). It uses output buffering to capture both returned and printed text.

Using this wrapper also ensures that the PHP code which is evaluated can not overwrite any variables in the calling code except the ones we need.

Parameters

string $code: A string containing the code to evaluate.

$data: The $data array passed on to token_replace().

$options: The $options array passed on to token_replace().

Return value

A string containing the printed output of the code, followed by the returned output of the code.

1 call to token_custom_eval()
token_custom_tokens in ./token_custom.module
Implements hook_tokens().

File

./token_custom.module, line 299
It gives the user the ability to create custom tokens using PHP code for specific replacements that can improve other modules relying on the token Drupal 7 core API.

Code

function token_custom_eval($code, $data, $options) {
  ob_start();
  print eval($code);
  $output = ob_get_contents();
  ob_end_clean();
  return $output;
}