help meeee

liunx

Guest
someone please help me because even calling myself a novice php programmer would be flattering myself. im working on my guestbook and ive been stuck on this for days.

i need a script that will delete the last 5 lines off the bottom of a document.

this why, my guestbook output file is an html file. what i need to make it do is when the form is submited it will send the info to redirdata.php that page needs to delete the last 5 lines off the bottom of the hml file, then post the message along with the html formatting, then the html code to close off the file. heres the page <!-- m --><a class="postlink" href="http://yzf.mine.nu/bruno/thawall.php">http://yzf.mine.nu/bruno/thawall.php</a><!-- m -->

I can make it do everything, EXCEPT make it delete the last 5 lines out of the document. i tried doing everything i can think of but my problem is i'm not good at the syntax for php.


SOMEONE PLEASE HELP ME!:(

--heres an example script that deletes a designated line from a file, i dont think it works cuz it didnt when i tested it:
<!-- m --><a class="postlink" href="http://www.phpbuilder.com/mail/php-general/2000071/2312.php">http://www.phpbuilder.com/mail/php-gene ... 1/2312.php</a><!-- m -->

--heres the script to post the message: <it works fine>

<?PHP

if (($_POST[message]) && ($_POST[name]) && ($_POST)) {
$filename = "guestbookfile.htm";
$ts = date("M/d/Y");
$fd = fopen($filename, "a+") or die("error: unable to submit post, please contact the website admin");

fwrite($fd, "_______________________ <br> \n <br> \n [$ts] <br> \n Name: $_POST[name] <br> \n E-Mail: $_POST[email] <br> \n Message: $_POST[message] <br> \n _______________________ </font></b></p> \n \n <body> \n </html> ");

fclose($fd);
}
?>Firstly, please read <!-- m --><a class="postlink" href="http://www.htmlforums.com/showthread.php?s=&threadid=12055">http://www.htmlforums.com/showthread.ph ... adid=12055</a><!-- m --> :)

This script reads a file (called post.html), strips the last 5 lines and writes the contents back (untested but should work).
<?php
$myFile = file ('post.html');
$myFile = array_slice($myFile, 0, sizeOf($myFile) - 5);

$fp = fopen('post.html', 'w');
foreach ($myFile as $line) {
fputs($fp, $line);
}

fclose($fp);
?>little curious.....

if he is using this to make the html file

fwrite($fd, "_______________________ <br> \n <br> \n [$ts] <br> \n Name: $_POST[name] <br> \n E-Mail: $_POST[email] <br> \n Message: $_POST[message] <br> \n _______________________ </font></b></p> \n \n <body> \n </html> ");

than if you cut off the last 5 lines than it would cu teh html off the end and then the page will be incomplete.

so why not just take the html out of the fwrite? ;)

fwrite($fd, "_______________________ <br> \n <br> \n [$ts] <br> \n Name: $_POST[name] <br> \n E-Mail: $_POST[email] <br> \n Message: $_POST[message] <br> \n _______________________");hey scout, i dont think you understood my question correctly. thanx to the help of torrent i actualy got my page doing exactly what i wanted. thanx man. but heres the completed script that im using. u can take a look and see if u have any other sugestions.

<?php
$myFile = file ('guestbook.php');
$myFile = array_slice($myFile, 0, sizeOf($myFile) - 4);

$fp = fopen('guestbook.php', 'w');
foreach ($myFile as $line) {
fputs($fp, $line);
}

fclose($fp);

if (($_POST[message]) && ($_POST[name]) && ($_POST[email])) {
$filename = "guestbook.php";
$ts = date("M/d/Y");
$fd = fopen($filename, "a+") or die("error: unable to submit post, please contact the website admin");

fwrite($fd, "_______________________ <br> \n <br> \n[$ts] <br> \nName: $_POST[name] <br> \nE-Mail: $_POST[email] <br> \nMessage: $_POST[message] <br> \n_______________________ </font></b></p> \n \n <body> \n </html>");

fclose($fd);
}
?>

so what it does is deletes the last bit of guestbook.php, posts the message and then completes the html. i named the that the posts get writen to .php because then it isnt cached and it solves the problem of the iframe that u view the posts in not refreshing each time.

see it in action: http:\\yzf.mine.nu\bruno\thawall.htmI didn't??????

tell me what last 5 lines you are cutting off? could it be this

fwrite($fd, "_______________________ <br> \n <br> \n[$ts] <br> \nName: $_POST[name] <br> \nE-Mail: $_POST[email] <br> \nMessage: $_POST[message] <br> \n_______________________ </font></b></p> \n \n <body> \n </html>");

because no where in your code are you starting the <html> tags.no dude, ok lets see if i can explain myself better. but before i do, i want to say the issue is resolved and the script posted up on the previous reply is a working script with no probs.

the page that i archive my posts on is guestbook.php (i named it .php because that way its not cached and is refreshed off the server each time).
when u type a message into the form on "thewall.htm" it sends the data to "redirdata.php" this is the page with the script on it. the script first cuts off the last five lines of HTML on guestbook.php.

the part of the script that does this is:

$myFile = file ('guestbook.php');
$myFile = array_slice($myFile, 0, sizeOf($myFile) - 4);

$fp = fopen('guestbook.php', 'w');
foreach ($myFile as $line) {
fputs($fp, $line);
}

fclose($fp);

the lines that are cutt off of guestbook.php are these ones:
_______________________ </font></b></p>

<body>
</html>

this part of the script posts the message being sent to the guestbook up and along with it the HTML code needed to close the file off:

if (($_POST[message]) && ($_POST[name]) && ($_POST[email])) {
$filename = "guestbook.php";
$ts = date("M/d/Y");
$fd = fopen($filename, "a+") or die("error: unable to submit post, please contact the website admin");

fwrite($fd, "_______________________ <br> \n <br> \n[$ts] <br> \nName: $_POST[name] <br> \nE-Mail: $_POST[email] <br> \nMessage: $_POST[message] <br> \n_______________________ </font></b></p> \n \n <body> \n </html>");

fclose($fd);
}
?>

i hope my script and my last post make sence now. im not too good with php or html so this is the easyiest and only way i could think of doing this. it works fine but lemme know if u have suggestions

see it in action: http:\\yzf.mine.nu\bruno\thawall.htm

dont worry about posting garbage in there i'll jus go delete it and clean it up. its all good. have fun but jus dont go nuttz.The last <body> should be </body>nevermind, I was thinking you didn't have any starting html in there. don't mind me :)no probs at all scout, now that i explained it so well if anyone ever needs to make a simple guestbook they could use this script. also if u take off the first part of the script that cuts the lines it'll just submit the form to a txt file. if someone does use this script its all good as long as thier page doesnt look like mine, (not that i'm claiming copy right or anything to this script because im not) but then again why would someone want thier page to look like mine cuz its so darn butt ugly. lol.

and torrent, yes perhaps ur right that <body> is supposed to be </body> but i use MS Frontpage to make my pages due to the fact i know nothing of html. its easy to use, maybe even the easyest but the HTML it spews out is purely crappola and anyone who knows html would shake thier head in disgust. but hey it works.

thanx for the help everyone. this is the best help forum ive ever come accross. the response times are completely unreal. im going to recomend this site to everyone who needs web help and then some. u guys rock :banger:

as long as u guys dont start charging money for memberships or something else completely typical like that.
 
Back
Top