我想閱讀PHP中匹配條件後中斷或退出的文本文件。PHP讀取文本文件,直到匹配條件時中斷
PHP代碼:
$file = fopen("testFile.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
$line = fgets($file, 1024);
if($line=="NOTE"){
break;
}
echo $line ."<br>";
}
fclose($file);
例
line1: i love u so much
line2: this is tom
Line3: note
Line: this is jam
結果需要:
當滿足說明會中斷。
line1: i love u so much
line2: this is tom
你會得到什麼輸出?你期望得到什麼輸出?該文件如何查看? – MeLight 2011-12-18 09:10:11
例 行1:我愛你那麼多 線路2:這是湯姆 3號線:注意 線:這是果醬 結果需要: 當滿足說明會中斷。 line1:我很愛你 line2:這是tom – 2011-12-18 09:14:43
第3行'note'或者'NOTE'? – 2011-12-18 09:17:11