In PHP possiamo separare un file di testo in righe.
La soluzione รจ la seguente:
function get_file_lines($file) {
$lines = [];
if(!file_exists($file) || !is_readable($file)) {
error_log("Cannot read $file", 0);
return $lines;
}
$mime = mime_content_type($file);
if($mime !== 'text/plain') {
error_log("Invalid format for $file", 0);
return $lines;
}
$contents = file_get_contents($file);
$lines = preg_split('/\n|\r\n/', $contents);
return $lines;
}