Welcome Guest, Not a member yet? Register   Sign In
Search for a certain function in all helper files?
#10

[eluser]sophistry[/eluser]
believe it or not, you are getting closer...

first of all, please post code with code blocks so it shows up with indents and syntax highlighting in the forum.

regex is a strange and wonderful thing. This is the thing that is "capturing" your function name.
Code:
(.+?)

The fact that the $matches_array has nothing in it means that something is wrong with the regex. It's probably the caret sign
Code:
^

that tells the regex to only look for the string "function" when it starts exactly at the start of a newline. probably not working because you have some spaces in there. try removing the caret and see what you get.

also, you don't need the $i - it isn't doing anything.

try this:
Code:
$helpers = glob(APPPATH.'helpers/*_helper.php');
foreach ($helpers as $line) {
// removed caret
preg_match('/function (.+?)\(/',$line,$matches_array);
echo var_dump( $matches_array );

}

if that regex doesn't work you can try this one:
Code:
preg_match('/function([^\(]+)/',$line,$matches_array);

that's a little different. it tells the regex engine to look for the string function and then captures anything up to the opening parentheses to the right of the function name.


Messages In This Thread
Search for a certain function in all helper files? - by El Forum - 08-14-2008, 04:27 AM
Search for a certain function in all helper files? - by El Forum - 08-14-2008, 04:42 AM
Search for a certain function in all helper files? - by El Forum - 08-14-2008, 08:48 AM
Search for a certain function in all helper files? - by El Forum - 08-14-2008, 08:59 AM
Search for a certain function in all helper files? - by El Forum - 08-14-2008, 11:40 AM
Search for a certain function in all helper files? - by El Forum - 08-14-2008, 12:13 PM
Search for a certain function in all helper files? - by El Forum - 08-14-2008, 04:10 PM
Search for a certain function in all helper files? - by El Forum - 08-14-2008, 05:12 PM
Search for a certain function in all helper files? - by El Forum - 08-15-2008, 04:26 AM
Search for a certain function in all helper files? - by El Forum - 08-15-2008, 07:31 AM
Search for a certain function in all helper files? - by El Forum - 08-15-2008, 11:43 AM
Search for a certain function in all helper files? - by El Forum - 08-15-2008, 02:14 PM
Search for a certain function in all helper files? - by El Forum - 08-17-2008, 06:39 AM
Search for a certain function in all helper files? - by El Forum - 08-17-2008, 09:04 AM
Search for a certain function in all helper files? - by El Forum - 08-18-2008, 01:55 AM
Search for a certain function in all helper files? - by El Forum - 08-18-2008, 02:23 AM
Search for a certain function in all helper files? - by El Forum - 08-18-2008, 06:08 AM
Search for a certain function in all helper files? - by El Forum - 08-18-2008, 06:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB