2014年2月5日 星期三

[PHP]Get Function List 取得函數列表


因為工作上的需求,會有這個需要

所以找了一下資料,在此記錄一下



# The Regular Expression for Function Declarations
$functionFinder = '/function[\s\n]+(\S+)[\s\n]*\(/';
# Init an Array to hold the Function Names
$functionArray = array();
# Load the Content of the PHP File
$fileContents = file_get_contents( 'function_list.php' );

# Apply the Regular Expression to the PHP File Contents
preg_match_all( $functionFinder , $fileContents , $functionArray );

# If we have a Result, Tidy It Up
if( count( $functionArray )>1 ){
  # Grab Element 1, as it has the Matches
  $functionArray = $functionArray[1];
}




print_r($functionArray);



來源網址:http://stackoverflow.com/questions/4622390/extracting-function-names-from-a-file-with-or-without-regular-expressions