php获取print的内容,放入变量

可以参考drupal的theme_render_template函数

function theme_render_template($template_file, $variables) {
  // Extract the variables to a local namespace
  extract($variables, EXTR_SKIP);

  // Start output buffering
  ob_start();

  // Include the template file
  include DRUPAL_ROOT . '/' . $template_file;

  // End buffering and return its contents
  return ob_get_clean();
}

主要用到2个函数,ob_start和ob_get_clean

原文地址:https://www.cnblogs.com/merryfreespace/p/3612530.html