title: How to get the function body out of a string containing a function?
body: <p>Heres the string:</p>
  
  <pre><code>&lt;?php
  $string = '//ps: this placeholder text to demonstrate issues..
  
  function go($url) {
  header("Location: {$url}");
  exit();
  }
  
  function some() {
  
  /* this is the function body */
  
  $result = mysql_query("SELECT something FROM sometable");
  while ($row = mysql_fetch_assoc($result)) {
  
  //something...
  }
  
  return "something";
  
  /* this is the function body */
  
  }
  
  function fetch2($result) {
  
  while ($row = mysql_fetch_assoc($result)) {
  
  //something...
  }
  
  return "something";
  
  }';
  ?&gt;
  </code></pre>
  
  <p>I've tried regex it works on some occasions and other occasions it doesn't (if there are braces within the function body I can't control the greedyness).</p>
  
  <p>This is what I tried:</p>
  
  <pre><code>preg_match('#function some\(\)\s*{(.+?)}#s', $string, $matches);
  
  echo $match[1];
  </code></pre>
  
  <p>However, this does not give me the complete function body due to the set of braces before the closing brace interfering with the matching.</p>
  
  <p>My question (ellaborated): How can I get the function body more reliably (without it being troublesome when theirs braces before the closing brace)? Someone suggested to use <code>token_get_all()</code> but I have no clue how to use it or what I should use it for.</p>