<?php


$str = <<<'EOF'
function testfunc($text) {
   if ($text) {
       return 1;
   }
   return 0;
}
EOF;
if ( preg_match('/ (function [^{]+ ) ( \{ (?: [^{}]* | (?-1) )* \} ) /x', $str, $m) )
   print_r ($m);

?>