file

(PHP 3, PHP 4 )

file -- Legge l'intero file in un vettore

Descrizione

array file ( string filename [, int use_include_path])

Identica a readfile(), eccetto per il fatto che file() restituisce il file in un vettore. Ogni elemento del vettore corrisponde ad una riga del file, con il carattere di newline ancora inserito.

Nota: Each line in the resulting array will include the line ending, so you still need to use trim() if you do not want the line ending present.

Puoi impostare il secondo parametro (opzionale) ad "1", se vuoi cercare il file nel include_path.

<?php
// inserisce una pagina web in un array e la stampa
$fcontents = file ('http://www.php.net');
while (list ($line_num, $line) = each ($fcontents)) {
    echo "&lt;b&gt;Line $line_num:&lt;/b&gt; " . htmlspecialchars ($line) . "&lt;br&gt;\n";
}

// inserisce una pagina web in una stringa
$fcontents = join ('', file ('http://www.php.net'));
?>

Nota: As of PHP 4.3.0 you can use file_get_contents() to return the contents of a file as a string in a binary safe manner.

Attenzione

Questa funzione non è (ancora) binary-safe! (non gestisce correttamente i file binari)

Suggerimento: È possibile utilizzare una URL come un nome di file con questa funzione se fopen wrappers è stata abilitata. Per maggiori informazioni su come specificare i nomi di file vedere fopen() e Appendice I per avere la lista dei protocolli URL supportati.

Vedere anche readfile(), fopen(), fsockopen() e popen().