Pagine

mercoledì 8 giugno 2011

Lettura file di testo

3csia.php
<html>
<head>
<title>Lettura in 3csia.txt dei cognomi e nomi</title>
</head>
<body>
<center>
<h2>Elenco della classe 3 C S.I.A</h2>
<?php
//Apertura del file 3csia.txt in lettura
$fp=fopen("3csia.txt","r");

//lettura delle righe del file
if ($fp) {
//Ciclo di iterazione pre-condizionale
echo "<table border='1'>";
while (!feof($fp)) {
$riga=fgets ($fp,100);
$cognom="";
for ($i=0;$i<strlen($riga);$i++) {
if (substr($riga,$i,1)<>"|")
$cognom=$cognom . substr($riga,$i,1);
else $i=strlen($riga);
}
echo "<tr>
<td>$cognom</td>
</tr>";
} echo "</table>";
fclose($fp);
}
else
echo "Il file non &egrave; stato trovato.";
?>
</center>
</body>
</html>

Nessun commento:

Posta un commento