欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

获取当前目录下所有php文件内的函数名

程序员文章站 2022-12-29 11:09:07
$dir = dirname(__FILE__); $files = scandir($dir); foreach($files as $name){ if($name == '.' || $name == '..'){ continue; } $title = preg_replace("/Con... ......
$dir =  dirname(__file__);

$files = scandir($dir);

foreach($files as $name){
if($name == '.' || $name == '..'){ continue; }
$title = preg_replace("/controller.*?php/",'',$name);
$file = fopen($name,"r"); $content = array(); while(!feof($file)){
$line_content = fgets($file);
preg_match("/public\s+function/", $line_content, $pat_array);
if(isset($pat_array[0])){
$line_content = preg_replace("/.*?function\b|\(.*?{|\s+/",'',$line_content); $content[] = $title.'/'.$line_content; } } fclose($file); print_r($content); }