Ver Mensaje Individual
  #2 (permalink)  
Antiguo 28/05/2008, 15:23
Avatar de eft0
eft0
 
Fecha de Ingreso: junio-2003
Ubicación: Santiago - Chile
Mensajes: 635
Antigüedad: 20 años, 10 meses
Puntos: 9
Respuesta: borrar una linea de un fichero

Google it's your best friend:

Código PHP:
<?php

// this function strips a specific line from a file
// if no linenumber is specified, last line is stripped
// if a line is stripped, functions returns True else false
//
// e.g.
// cutline('foo.txt'); // strip last line
// cutline('foo.txt',1); // strip first line

/* its probably a good idea to allow access to this file via a password. otherwise, anyone that knows its in your directory could delete lines of text from the file you specify below! */

function cutline($filename,$line_no=-1) {

$strip_return=FALSE;

$data=file($filename);
$pipe=fopen($filename,'w');
$size=count($data);

if(
$line_no==-1$skip=$size-1;
else 
$skip=$line_no-1;

for(
$line=0;$line<$size;$line++)
if(
$line!=$skip)
fputs($pipe,$data[$line]);
else
$strip_return=TRUE;

return 
$strip_return;
}

cutline('foo.txt',6); // deletes line 6 in foo.txt
}
?>
__________________
eft0's stuff! - http://estebanfernandez.net