读取函数块php中的行

读取函数块php中的行,php,Php,首先我读取文件,如果该行包含function关键字,我想读取函数块中的行。我的文件结构是 function some_method2() { one; } function some_method3() { two; return; } 我正在使用while(FALSE!=($line=fgets($readfile)){像这样如何使用next()?请检查此项以了解有关SplFileObject的更多信息,您可以使用fgets()逐行读取循环中的内容。要了解fgets单

首先我读取文件,如果该行包含
function
关键字,我想读取函数块中的行。我的文件结构是

function some_method2() {
    one;
}
function some_method3() {
    two;
    return;
}
我正在使用while(FALSE!=($line=fgets($readfile)){像这样如何使用next()?请检查此项以了解有关SplFileObject的更多信息,您可以使用
fgets()
逐行读取循环中的内容。要了解
fgets
单击。
$obj = new SplFileObject('filename','r+');
while(!$obj->eof()){
$curr_line = $obj->current();
if(strpos($curr_line,"function" )!==false){
$obj->next();
while(strpos($obj->current(),'}')!== true)
{
$body .= $obj->current();
$obj->next();
} 
}
else{
$obj->next();
}
}