Ciao Ragazzi! Ho un problema con gli oggetti.
Ho questo piccolo script importa un file di testo(studenti.txt) nel seguente formato: Cognome#Nome#Matricola#Materia1#Materia2#Materia3 e tramite l'explode, mi spezzetto le righe e stampo i dati in una tabella
Codice PHP:
<TABLE>
<TR>
<TD>COGNOME</TD><TD>NOME</TD><TD>MATRICOLA</TD><TD>MATERIA1</TD><TD>MATERIA2</TD><TD>MATERIA3</TD>
</TR>
<?
$studenti = file("studenti.txt");
for($i=0; $i<count($studenti); $i++)
{
$S1 = explode("#",$studenti[$i]);
$cognome = $S1[0];
$nome = $S1[1];
$matricola = $S1[2];
$materia1 = $S1[3];
$materia2 = $S1[4];
$materia3 = $S1[5];
echo "<TR><TD>".$cognome."</TD><TD>".$nome."</TD>
<TD>".$matricola."</TD><TD>".$materia1."</TD>
<TD>".$materia2."</TD><TD>".$materia3."</TD>
</TR>";
}
?>
</TABLE>
Ma se devo fare la stessa cosa, con gli oggetti e crearmi una classe così:
Codice PHP:
class student
{
function leggistudenti()
{
$studenti = file("studenti.txt");
for($i=0; $i<count($studenti); $i++)
{
$S1 = explode("#",$studenti[$i]);
$cognome = $S1[0];
$nome = $S1[1];
$matricola = $S1[2];
$materia1 = $S1[3];
$materia2 = $S1[4];
$materia3 = $S1[5];
}
}
}
come faccio a crearmi una tabella fuori dalla classe richiamando i dati che mi servono?