Imploding an empty array

Hello again. -_-
I'm using a crazy text file based system for the news on my site. It works like this...

I have a file, called news.foo, which looks something like this:
[code]
Title
Author
Date
Content

Title2
Author2
Date2
Content2

etc...
[/code]
Notice that each news article is separated by two new lines(

) and each part of those is separated by one(
).

I explode this file by

to separate the parts, so now I have:[code]$exploded[0] == "Title
Author
Date
Content";
$exploded[1] == "Title2
Author2
Date2
Content2";
[/code]
Then, to separate them even more, I explode each element of $exploded by
... So I have:
[code]
$exploded[0][0] == "Title"
$exploded[0][1] == "Author"
$exploded[0][2] == "Date"
$exploded[0][3] == "Content"
$exploded[1][0] == "Title2"
$exploded[1][1] == "Author2"
$exploded[1][2] == "Date2"
$exploded[1][3] == "Content2"
[/code]

I've got the code for displaying these in a formatted page working. I've got the code for editing these working also. But the problem is in deleting them.

To delete or modify entries, I change part of the array, then implode it and write the imploded string. With modifying it, I have no trouble. But, I'm having trouble in deleting entries, because sometimes it ends up trying to implode an empty array. Here's my code for getting around that. I don't see the problem. -_-
[code]
if ($_GET['q'] == "delete")
{
unset($exploded[$_GET['c']]);
//---------------------------------------------------------------------------------------------
// implode the parts, then implode them all together
foreach ($exploded as $index => $line) // Go through each part of $exploded
{
$implodedFirst[$index] = implode("
", $line); // Implodes each part
// by new line.
}
if(!is_null($implodedFirst[0])) // Make sure there is at least one element
{
$imploded = implode("

", $implodedFirst); // Implode by 2x new line...
}
else // If there are no elements
{
$imploded = "";
}
fputs($Fopened, $imploded);
fclose($Fopened);
//---------------------------------------------------------------------------------------------
$middleHTML = 'The entry was deleted.';
}
[/code]

Comments

  • Eh...
    No Ideas? Does anyone need some clarification?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion