Created
September 9, 2019 00:39
-
-
Save komputronika/f92397b4f60870131ef52930faf09983 to your computer and use it in GitHub Desktop.
Find all functions in a file and return it's names in array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//-------------------------------- | |
// Example usage: | |
//-------------------------------- | |
print "<pre>"; | |
print_r( functions_in_file(__FILE__) ); | |
//-------------------------------- | |
// Find functions in a file: | |
//-------------------------------- | |
function functions_in_file($file, $sort = FALSE) { | |
$file = join("\n",file($file)); | |
preg_match_all('/function\s+(\w+)/', $file, $m); | |
$functions = $m[1]; | |
if ($sort) { | |
asort($functions); | |
} | |
return $functions; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment