DeadlySin3
11-17-2002, 08:02 PM
<html>
<head>
<title>removing lines from a file</title>
</head>
<body>
<?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
if ( isset( $admin ) ) {
require("variables.php");
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('$testdoc',$deltag); // defined in variables.php
}
?>
<?php if ( isset( $admin ) ) { echo "Tag number $deltag has been deleted!"; }
else { echo "You need to <a href=\"adminIn.php\">login</a> before you can delete tags"; } ?>
<?php if ( isset( $admin ) ) { echo "<a href=\"javascript:history.back(1)\"> go back</a>"; } ?>
</body>
</html>
I found this lil bit of code while surfing the net - I set up a test tagboard, posted about 20 tags, and went through and picked lines to delete randomly. It works - but my question is, is it safe?
<head>
<title>removing lines from a file</title>
</head>
<body>
<?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
if ( isset( $admin ) ) {
require("variables.php");
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('$testdoc',$deltag); // defined in variables.php
}
?>
<?php if ( isset( $admin ) ) { echo "Tag number $deltag has been deleted!"; }
else { echo "You need to <a href=\"adminIn.php\">login</a> before you can delete tags"; } ?>
<?php if ( isset( $admin ) ) { echo "<a href=\"javascript:history.back(1)\"> go back</a>"; } ?>
</body>
</html>
I found this lil bit of code while surfing the net - I set up a test tagboard, posted about 20 tags, and went through and picked lines to delete randomly. It works - but my question is, is it safe?