function views_var_export

3.x views.module views_var_export($var, $prefix = '', $init = TRUE)
2.x views.module views_var_export($var, $prefix = '', $init = TRUE)

Export a field.

2 calls to views_var_export()
view::export in includes/view.inc
Export a view as PHP code.
views_db_object::export_row in includes/view.inc
Export a loaded row, such as an argument, field or the view itself to PHP code.

File

./views.module, line 1244
Primarily Drupal hooks and global API functions to manipulate views.

Code

function views_var_export($var, $prefix = '', $init = TRUE) {
  if (is_array($var)) {
    if (empty($var)) {
      $output = 'array()';
    }
    else {
      $output = "array(\n";
      foreach ($var as $key => $value) {
        $output .= "  " . views_var_export($key, '', FALSE) . " => " . views_var_export($value, '  ', FALSE) . ",\n";
      }
      $output .= ')';
    }
  }
  else if (is_bool($var)) {
    $output = $var ? 'TRUE' : 'FALSE';
  }
  else if (is_string($var) && strpos($var, "\n") !== FALSE) {
    // Replace line breaks in strings with a token for replacement
    // at the very end. This protects multi-line strings from
    // unintentional indentation.
    $var = str_replace("\n", "***BREAK***", $var);
    $output = var_export($var, TRUE);
  }
  else {
    $output = var_export($var, TRUE);
  }

  if ($prefix) {
    $output = str_replace("\n", "\n$prefix", $output);
  }

  if ($init) {
    $output = str_replace("***BREAK***", "\n", $output);
  }

  return $output;
}