title: Can we store echoed text in a variable in PHP?
body: <p>When I call a function of another class (in a included file), some text is being output with <code>echo</code>. I need to store this in a variable.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>require_once('../restapis/api.php');
  
  class ApiTest
  {
      public function testapis(){
         $api = new Api();
         $api-&gt;validate_request();
      }
  }
  
  $obj = new ApiTest();
  $obj-&gt;testapis();
  </code></pre>
  
  <p>And I am getting a JSON string echoed in browser:</p>
  
  <pre><code>{"ERRORCODE":"E032","ERRORMESSAGE":"Invalid URL."}
  </code></pre>
  
  <p>I don't have permission to change anything in the <code>api.php</code> file, that's why I can't change <code>echo</code> to <code>return</code>.</p>
  
  <p>Is there any way I can do this?</p>