Can anyone tell me please how I can skip the first and the last line a file. I wrote two functions that return the first and the last line of a file but I need a the lines between the header and the tail !
function get_file_header($file) {
return fgets($file);
}
function get_file_tail($file){
while (( $line = fgets($file) )){
$fin = $line;
}
return $fin;
}
You could read the lines in an array first with file
and then perform the removal with array_slice
:
function get_file_tail($filepath){
// Read file as lines into an array
$lines = file($filepath);
// Remove first and last line
$lines = array_slice($lines, 1, count($lines)-2);
// Convert to string (if array is not useful for you) and return it
return implode(PHP_EOL, $lines);
}
Example call:
echo get_file_tail("http://websitetips.com/articles/copy/lorem/ipsum.txt");
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras