Over the last few months I have been learning PHP and adding things to my website to make it easier. So I created a script that would allow me to create pages and then edit them later. The pages are stored in a separate PHP file to save on extraneous files and make it easier to back things up. This is the code that I have for opening it:
Please excuse how sloppy this code is, it is all jumbled up from me tinkering with it.
include("../page-store.php");
$n = (count($page));
$n == $n--;
$num = $n;
echo("<center><form method=post action=edit-page.php><select name=page_num>");
for($n; 0 <= $n ; $n--)
{
if($n < $num)
{
$num2 = $num;
echo("<option value=$num selected>" . $num2++ . " | " . $page[$n][0] . "</option>");
$num == $num--;
}
else
{
$num2 = $num+1;
echo("<option value=$num>" . $num2++ . " | " . $page[$n][0] . "</option>");
$num == $num--;
}
};
echo("</select><BR><input type=submit value=\"Load Page\"></form></center><hr>");
if(isset($page_num))
{
$title_form = $page[$page_num][0];
$imgtitle_form = $page[$page_num][1];
$content_form = $page[$page_num][2];
echo("
<form method=post action=edit-page-finish.php>
<b>Title of Page</b><br>
<input type=text name=title size=50 value=\"" . $title_form . "\"><br>
<b>Title Image</b><br>
<input typ=text name=imgtitle value=\"" . $imgtitle_form . "\"><br>
<b>Content</b><br>
<textarea width=100% height=70px name=content rows=30 cols=83>" . $content_form . "</textarea><br>
<input type=hidden name=key value=\"" . $title_form . "\">
<input type=submit value=Edit Page>
</form>
");
}
else
{
echo("
Select a page from above
");
}
And here is the code for what actually writes to the file:
$epage = "\$page[] = array(\"$title\",\"$imgtitle\",\"$content\"); \r";
$fupdate = file("../page-store.php");
$open = fopen("../page-store.php", "w");
foreach($fupdate as $line)
{
if (!strstr($line, $key1))
{
fputs($open, $line);
}
else
{
fputs($open, $epage);
}
}
fclose($open);
When it is all said and done it should look like this. The problem is that when I go to edit it, it searches for the line that I need to edit and starts replacing it. The problem is that when it gets to a certain spot (it is the same spot every time), it stops replacing text and just places the new page right in front of where it stopped in the old page.
What I don't understand is, is there a certain amount of characters that is the max amount for a line? Or is a line in PHP limitless like I think it should be. Because I can't find any reason for it to be randomly stop deleting part of a line and just place everything else in front of it.
For anyone who wants to look, this is the source of the file that is storing the page info. This is when everything has gone haywire. Note that about half way through the line ends and then you can see where the pointer stopped because it contines on with "the cars..." from the original version. Please excuse the excess slashes, I am still working on those.
Any help would be appreciated. I haven't had any luck with the people I have asked so far.
[edit]And now I notice the coding forum. I am a real moron.