Открыть файл, читать строки, закройте файл:
// Open the file for reading
$file = 'file.txt';
$fh = fopen($file, 'rb');
// Handle failure
if ($fh === false) {
die('Could not open file: '.$file);
}
// Loop 3 times
for ($i = 0; $i < 3; $i++) {
// Read a line
$line = fgets($fh);
// If a line was read then output it, otherwise
// show an error
if ($line !== false) {
echo $line;
} else {
die('An error occurred while reading from file: '.$file);
}
}
// Close the file handle; when you are done using a
// resource you should always close it immediately
if (fclose($fh) === false) {
die('Could not close file: '.$file);
}
использовать файл '()' и получить индексы '0-2' – Ghost
вы можете получить представление оттуда http://stackoverflow.com/questions/13246597/how-to-read-a-file-line-by-line-in-php. Если вы это сделаете, вы получите дополнительную помощь. –
Как? можете ли вы дать мне правильный код? Я думаю, это не очень сложно, но мне нехорошо открывать/редактировать/читать файлы в PHP. – user2701811