title: A PHP regex to extract php functions from code files
body: <p>I'm trying to make a PHP regex to extract functions from php source code. Until now i used a recursive regex to extract everything between {} but then it also matches stuff like if statements. When i use something like:</p>
  
  <pre><code>preg_match_all("/(function .*\(.*\))({([^{}]+|(?R))*})/", $data, $matches);
  </code></pre>
  
  <p>It doesn't work when there is more than 1 function in the file (probably because it uses the 'function' part in the recursiveness too).</p>
  
  <p>Is there any way to do this?</p>
  
  <p>Example file:</p>
  
  <pre><code>&lt;?php
  if($useless)
  {
    echo "i don't want this";
  }
  
  function bla($wut)
  {
    echo "i do want this";
  }
  ?&gt;
  </code></pre>
  
  <p>Thanks</p>