0
起初我讀取文件,如果行中包含function
關鍵字,我想讀取功能塊內的行。我的文件結構是閱讀功能塊內的行php
function some_method2() {
one;
}
function some_method3() {
two;
return;
}
起初我讀取文件,如果行中包含function
關鍵字,我想讀取功能塊內的行。我的文件結構是閱讀功能塊內的行php
function some_method2() {
one;
}
function some_method3() {
two;
return;
}
$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();
}
}
我使用一段時間(FALSE!==($行=與fgets($ ReadFile的))){一樣,未來如何使用()? – phyo
請查看[link](http://php.net/manual/en/class.splfileobject.php)瞭解更多關於SplFileObject的信息。 您可以使用'fgets()'在循環內逐行讀取。要了解'fgets'點擊[這裏](http://php.net/manual/en/function.fgets.php)。 –
謝謝你......真正的工作:D – phyo