Fsoft
05-20-2008, 08:20 PM
HI,
I am new here. I need help> I am stuck in my project
My work, I mean I am trying to do is that first show all the contents of my text file. With each having a Text [Delete!] and after, once any one of them is clicked, It will delete that line from the text file database and imploded(); the lines again and write back to database. Now the code I am using is this ;
<?php
$db = "commentsdb.txt";
if($_GET["delete"])
{
$data = file($db);
foreach($data as $entry)
{
$data_remove = array_diff($entry , array($data));
}
implode("",$data_remove);
$handle = fopen($db,'w');
fwrite($handle,$data_remove);
fclose($handle);
}else
$data = file($db);
foreach($data as $entry)
{
echo $entry . "<a href='moderation.php?delete=" . $entry . "'>[Delete!]</a>";
}
?>
All goes Ok, It shows as I want. But the problem is once I hit a delete on next page I get these errors
Warning: array_diff() [function.array-diff]: Argument #1 is not an array in C:\server\htdocs\moderation.php on line 12
Warning: array_diff() [function.array-diff]: Argument #1 is not an array in C:\server\htdocs\moderation.php on line 12
Warning: array_diff() [function.array-diff]: Argument #1 is not an array in C:\server\htdocs\moderation.php on line 12
Warning: implode() [function.implode]: Invalid arguments passed in C:\server\htdocs\moderation.php on line 14
Thanks i Badly need help
Thanks a lot :)
edit,
I just saw a thread saying that this work can done with str_replace(); and it's more easier So I don't mind. If the array_diff(); Don't work :) I can easily work with str_replace(); can any one suggest me how can I use that function according to my script needs :) Thanks a lot :)
FAISAL!
I am new here. I need help> I am stuck in my project
My work, I mean I am trying to do is that first show all the contents of my text file. With each having a Text [Delete!] and after, once any one of them is clicked, It will delete that line from the text file database and imploded(); the lines again and write back to database. Now the code I am using is this ;
<?php
$db = "commentsdb.txt";
if($_GET["delete"])
{
$data = file($db);
foreach($data as $entry)
{
$data_remove = array_diff($entry , array($data));
}
implode("",$data_remove);
$handle = fopen($db,'w');
fwrite($handle,$data_remove);
fclose($handle);
}else
$data = file($db);
foreach($data as $entry)
{
echo $entry . "<a href='moderation.php?delete=" . $entry . "'>[Delete!]</a>";
}
?>
All goes Ok, It shows as I want. But the problem is once I hit a delete on next page I get these errors
Warning: array_diff() [function.array-diff]: Argument #1 is not an array in C:\server\htdocs\moderation.php on line 12
Warning: array_diff() [function.array-diff]: Argument #1 is not an array in C:\server\htdocs\moderation.php on line 12
Warning: array_diff() [function.array-diff]: Argument #1 is not an array in C:\server\htdocs\moderation.php on line 12
Warning: implode() [function.implode]: Invalid arguments passed in C:\server\htdocs\moderation.php on line 14
Thanks i Badly need help
Thanks a lot :)
edit,
I just saw a thread saying that this work can done with str_replace(); and it's more easier So I don't mind. If the array_diff(); Don't work :) I can easily work with str_replace(); can any one suggest me how can I use that function according to my script needs :) Thanks a lot :)
FAISAL!