阅读功能块php中的行

时间:2015-12-31 05:26:11

标签: php

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

function some_method2() {
    one;
}
function some_method3() {
    two;
    return;
}

1 个答案:

答案 0 :(得分:0)

$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();
}
}