title: How to pass the require_once output to a variable?
body: <p>I want to call require_once("test.php") but not display result and save it into variable like this:</p>
  
  <pre><code>$test = require_once('test.php');
  
  //some operations like $test = preg_replace(…);
  
  echo $test;
  </code></pre>
  
  <p><strong>Solution:</strong></p>
  
  <p>test.php</p>
  
  <pre><code>&lt;?php
  $var = '/img/hello.jpg';
  
  $res = &lt;&lt;&lt;test
  
  &lt;style type="text/css"&gt;
  body{background:url($var)#fff !important;}
  &lt;/style&gt;
  
  test;
  
  return $res;
  ?&gt;
  </code></pre>
  
  <p>main.php</p>
  
  <pre><code>&lt;?php
  $test = require_once('test.php');
  
  echo $test;
  ?&gt;
  </code></pre>