A PHP regex to extract php functions from code files
Posted
by user298593
on Stack Overflow
See other posts from Stack Overflow
or by user298593
Published on 2010-03-21T20:00:15Z
Indexed on
2010/03/21
20:11 UTC
Read the original article
Hit count: 301
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: preg_match_all("/(function .(.))({([^{}]+|(?R))*})/",$this->data,$matches2);
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).
Is there any way to do this?
Example file:
<?php
if($useless)
{
echo "i don't want this";
}
function bla($wut)
{
echo "i do want this";
}
?>
Thanks
© Stack Overflow or respective owner