Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Leggere txt

  1. #1
    Utente di HTML.it L'avatar di DjBart
    Registrato dal
    Jan 2009
    Messaggi
    346

    Leggere txt

    Salve
    Dovrei leggere un txt , fino a qui ci siamo , ora come posso fare in modo che prende solamente le ultime 10 righe di scrittura ?
    esempio
    se nel txt ho
    ciao 1,
    ciao 2,
    ciao 3,
    ciao 4,
    ciao 5,

    Vorrei stampare a video solamente
    ciao 4,
    ciao 5,
    come posso fare ??
    Grazie in anticipo

  2. #2
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Qual'è il tuo codice per leggere il file txt ?
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

  3. #3
    Utente di HTML.it L'avatar di DjBart
    Registrato dal
    Jan 2009
    Messaggi
    346
    Uso questo codice qua

    Codice PHP:
                $conta_td 1;         $numero_td 1;        echo " <table class=\"table table-striped table-bordered table-hover\"> <tbody>";        $f fopen("Func/form_ipn.log""r");        while (!feof($f)) {        $array explode(",",fgets($f));        $row current$array );        if ($conta_td == 1)        echo  "<tr>";        echo"<td>$row </td>";         if ($conta_td == $numero_td) {         echo  "</tr>";        $conta_td 1;        } else {        $conta_td++;        }        }        if ($conta_td!= 1) {        while ($conta_td <= $numero_td) {        echo  "<td>&nbsp;</td>";        $conta_td++;        }         echo"</tr>";         }          echo  " </tbody></table>"

  4. #4
    Ho riscritto il tuo codice in maniera più leggibile:
    Codice PHP:
    $conta_td 1;
    $numero_td 1;
    echo 
    " <table class=\"table table-striped table-bordered table-hover\"> <tbody>";
    $f fopen("Func/form_ipn.log""r");
    while (!
    feof($f)) {
        
    $array explode(",",fgets($f));
        
    $row current$array );
        if (
    $conta_td == 1)
            echo  
    "<tr>";
        echo
    "<td>$row </td>";
        if (
    $conta_td == $numero_td) {
            echo  
    "</tr>";
            
    $conta_td 1;
        } else {
            
    $conta_td++;
        }
    }
    if (
    $conta_td!= 1) {
        while (
    $conta_td <= $numero_td) {
            echo  
    "<td>&nbsp;</td>";
            
    $conta_td++;
        }
        echo
    "</tr>";
    }
    echo  
    " </tbody></table>"
    Spero tu sappia che, per come li hai messi, $conta_td e $numero_td rimangono sempre a 1 per tutto il tempo, e quindi l'else dentro il while e l'if fuori dall'while non sono mai eseguiti.

    A parte questo, puoi estrarre le ultime N righe di un file in due secondi così, anziché usare while(!feof($f)) e fgets e current:
    Codice PHP:
    $N 2;
    $tutte_le_righe file('Func/form_ipn.log');
    $ultime_righe array_slice($tutte_le_righe, -$N); 
    dove $tutte_le_righe è un array e $ultime_righe è un array ridotto estrapolando $N righe dalla fine dell'array.

  5. #5
    Utente di HTML.it L'avatar di DjBart
    Registrato dal
    Jan 2009
    Messaggi
    346
    Grazie mille per la risposta , sono riuscito a risolvere
    Grazie ancora

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.