Cancellare le prime 3 righe di un file

max_400

Utente Attivo
23 Gen 2009
770
0
16
caltanissetta
max400.forumfree.it
Sintetico e veloce come faccio a cancellare le prime 3 righe o piu di 3 di un file (.txt. html .php)

Ho creato una chat e ogni volta che un utente si collega viene inviato l'orario ogni minuto circa
però ovviamente l'elenco diventa troppo lungo come faccio a cancellare le prime righe che non mi interessano?Per esempio oggi è martedi devo cancellare le righe di ieri magari qualkosa che legge la parola Monday e cancella la righe relativa voi che siete bravi di php.


- Monday, 22 September 2014 - 11:40
- Monday, 22 September 2014 - 20:18
- Monday, 22 September 2014 - 20:21
- Monday, 22 September 2014 - 20:24
- Monday, 22 September 2014 - 20:25
- Monday, 22 September 2014 - 20:26
- Monday, 22 September 2014 - 20:27
- Monday, 22 September 2014 - 20:31
- Monday, 22 September 2014 - 20:32
- Monday, 22 September 2014 - 20:33
- Monday, 22 September 2014 - 20:34
- Monday, 22 September 2014 - 20:35
- Monday, 22 September 2014 - 20:36
- Monday, 22 September 2014 - 20:37
- Monday, 22 September 2014 - 20:38
- Monday, 22 September 2014 - 20:39
- Monday, 22 September 2014 - 20:40
- Monday, 22 September 2014 - 20:41
- Monday, 22 September 2014 - 20:42
- Monday, 22 September 2014 - 20:43
- Monday, 22 September 2014 - 20:45
- Monday, 22 September 2014 - 21:01
- Monday, 22 September 2014 - 21:02
- Monday, 22 September 2014 - 21:03
- Monday, 22 September 2014 - 21:04
- Monday, 22 September 2014 - 21:05
- Monday, 22 September 2014 - 21:14
- Monday, 22 September 2014 - 21:23
- Monday, 22 September 2014 - 21:27
- Monday, 22 September 2014 - 21:28
- Monday, 22 September 2014 - 21:30
- Monday, 22 September 2014 - 21:31
- Monday, 22 September 2014 - 21:32
- Monday, 22 September 2014 - 21:33
- Monday, 22 September 2014 - 21:34
- Monday, 22 September 2014 - 21:35
- Monday, 22 September 2014 - 21:36
- Monday, 22 September 2014 - 21:37
- Monday, 22 September 2014 - 21:38
- Monday, 22 September 2014 - 21:40
- Monday, 22 September 2014 - 21:41
- Monday, 22 September 2014 - 21:42
- Monday, 22 September 2014 - 21:43
- Monday, 22 September 2014 - 21:44
- Monday, 22 September 2014 - 21:45
- Monday, 22 September 2014 - 21:46
- Monday, 22 September 2014 - 21:47
- Monday, 22 September 2014 - 21:48
- Monday, 22 September 2014 - 21:49
- Monday, 22 September 2014 - 21:51
- Monday, 22 September 2014 - 21:51
- Monday, 22 September 2014 - 21:53
- Monday, 22 September 2014 - 21:53
- Monday, 22 September 2014 - 21:55
- Monday, 22 September 2014 - 21:56
- Monday, 22 September 2014 - 21:58
- Monday, 22 September 2014 - 22:01
- Monday, 22 September 2014 - 22:03
- Monday, 22 September 2014 - 22:04
- Monday, 22 September 2014 - 22:05
- Monday, 22 September 2014 - 22:06
- Monday, 22 September 2014 - 22:07
- Monday, 22 September 2014 - 22:08
- Monday, 22 September 2014 - 22:09
- Monday, 22 September 2014 - 22:10
- Monday, 22 September 2014 - 22:11
- Monday, 22 September 2014 - 22:12
- Monday, 22 September 2014 - 22:13
- Monday, 22 September 2014 - 22:14
- Monday, 22 September 2014 - 22:15
- Monday, 22 September 2014 - 22:19
- Monday, 22 September 2014 - 22:20
- Monday, 22 September 2014 - 22:29
- Monday, 22 September 2014 - 22:30
- Monday, 22 September 2014 - 22:31
- Monday, 22 September 2014 - 22:38
- Monday, 22 September 2014 - 22:39
- Monday, 22 September 2014 - 22:40
- Monday, 22 September 2014 - 22:42
- Monday, 22 September 2014 - 23:23
- Monday, 22 September 2014 - 23:24
- Tuesday, 23 September 2014 - 10:04
- Tuesday, 23 September 2014 - 10:09
- Tuesday, 23 September 2014 - 13:32
- Tuesday, 23 September 2014 - 14:01
- Tuesday, 23 September 2014 - 14:15


grazie
 

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
Ciao Max
apri due volte il file, una volta in lettura, cerchi il giorno e prepari una stringa, una volta in scrittura e sovrascrivi
PHP:
<?php

$oggi = date("l");
$file = "file.txt";

$fr = fopen($file, 'r');
$nuovo = "";
while (!feof($fr)) {
    $riga = fgets($fr);
    if (strpos($riga, $oggi) !== false) {
        $nuovo .= $riga;
    }
}
fclose($fr);

$fr = fopen($file, 'w');
fwrite($fr, $nuovo);
fclose($fr);
?>
 

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
Se passi la mattina va bene altrimenti basta un birra :beer: