2013-06-12 45 views

回答

1

您應該遍歷數組$lines,然後將該鍵加1以獲得下一行。

$lines = file("input.txt"); 

$return = array(); 
foreach($lines as $key => $line) { 
    if(false !== strpos($line,'--><--')) { 
     // check if there is another line in the file 
     if(isset($lines[($key+1)])) { 
      // add the line to array 
      $return[] = $lines[($key+1)]; 
     } 
    } 
} 
print_r($return); 
0

我不知道,如果你匹配一個Windows或Unix文件(因此\r?),但你可以使用正則表達式更乾淨做到這一點。你可以這樣捕獲它:

$lines = file("input.txt"); 
preg_match('!(--><--\r?\n)([^\r\n]+)\r?\n!s',$lines,$matches); 
$myLine = $matches[2]; 
echo $myLine; 
相關問題