title: Replacing string with a function that outputing data already
body: <p>I'm trying to replace a string with a function which already displays data or you can echo data already</p>
  
  <pre class="lang-php prettyprint-override"><code>    function getData(){
          //echoing data from database, loop
          echo 'printing output';
      }
  
       function output(){
          return getData();
      }
  </code></pre>
  
  <p>And here is the string</p>
  
  <pre class="lang-php prettyprint-override"><code>    $str = "This is some text with php code &lt;?php output();?&gt;";
  </code></pre>
  
  <p>I tried str_replace like this</p>
  
  <pre><code>str_replace("&lt;?php output();?&gt;", output(), $str);
  </code></pre>
  
  <p>The problem is that it displays data already when I <code>str_replace</code> to replace the code with function. And i also tried other function like <code>preg_replace()</code> and <code>preg_replace_callback()</code></p>