Page 1 of 1
Extra line breaks being added in form upload
Posted: Wed Oct 01, 2003 5:16 am
by mesz

Dear All,
I must please ask for your help again.
( this is a problem that has been annoying me since I first coded php and I have never fixed...please, please help! )
Essentially the problem is that if I either look at the form upload page
( addnews.php ) and
don't enter data and then look at the page which displays the data
( view.php ) - extra line breaks are added to the display page.
If I am not using a form or table to display the results I don't get extra physical lines displayed, but the text is moved down the page.
...both are annoying...please help...
addnews.php
Code: Select all
<?php
<?
$fp = fopen('./news.txt','a+');
if (!$fp) {
echo "Sorry could'n open file!";
} else {
if($HTTP_POST_VARS['submit'])
$fp = fopen('./news.txt','a+');
$line = $HTTP_POST_VARS['date'] . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("\r\n","<br>",$line);
$line .= "\r\n";
fwrite($fp, $line);
}
?>
?>
view.php
Code: Select all
<?php
<?PHP
$data = file('./news.txt');
$data = array_reverse($data);
foreach($data as $element) {
$element = trim($element);
$pieces = explode("|", $element);
echo "<form class="form"><b>". $pieces[1] . "</b>" . $pieces[0]. "</form>" ;
echo "<form class="form">" . $pieces[2] . "</form>" ;
}
?>
?>
Posted: Wed Oct 01, 2003 6:21 am
by twigletmac
Could we see the HTML output (a bit of the problem area)?
Mac
Posted: Wed Oct 01, 2003 6:28 am
by mesz
Cheers for your help.....
I have included a screen shot at this address,
http://www.distortedmedia.co.uk/error.doc
( I couldn't post a link to the actual page becasue it is in a secured directory )
Posted: Wed Oct 01, 2003 6:34 am
by jason
Hrm..maybe in a non .doc format.
Many of us here don't use Windows.
And opening up a .doc is, well, a painful experience.
Posted: Wed Oct 01, 2003 6:36 am
by mesz
of course...I forget about the feelings of you lot to windows....
give me a moment....
Posted: Wed Oct 01, 2003 6:51 am
by mesz
here you go -
http://www.saua.co.uk/internal/view.php( as it is not finished I have taken security away.)
Posted: Wed Oct 01, 2003 6:52 am
by Derfel Cadarn
Isn't this just double? (in the file addnews.php)
$line = str_replace("\r\n","<br>",$line);
$line .= "\r\n";
Seems to me you'll get two new lines here. I played with it and I got the following output:
Code: Select all
<form class="form"><b></b>news: nog steeds nix</form>
<form class="form"></form>
<form class="form"><b></b>name: ik</form>
<form class="form"></form>
<form class="form"><b></b>date: 2003-5-2</form>
<form class="form"></form>
<form class="form"><b></b>news: niks</form>
<form class="form"></form>
<form class="form"><b></b>name: ad</form>
<form class="form"></form>
<form class="form"><b></b>date: 2003-6-9</form>
<form class="form"></form>
Posted: Wed Oct 01, 2003 7:08 am
by mesz
I have not been able to solve the problem from your advice. I appreciate the help, but I know I need to play with it a little, I just don't know what I need to do...
Posted: Wed Oct 01, 2003 7:18 am
by Derfel Cadarn
Can we have a look at a bit of your .txt-file? It seems to be different from the one I used.
And to be honoust: that "onload screen-maximize" is quite annoying, it would chase me away from the site!
Posted: Wed Oct 01, 2003 7:21 am
by mesz
the text file is just a blank text file, nothing more nothing less.
Posted: Wed Oct 01, 2003 7:48 am
by Derfel Cadarn
I guess it has to do with the <form>-tags: I replaced them with <div>-tags and the empty lines in the HTML-code were gone...
Edit: And I think the lines with just two || (also without text) AND the lines with more than two || in the txt-file cause problems for the script: that's where empty lines arise!
Posted: Wed Oct 01, 2003 8:05 am
by mesz
Derfel Cadarn wrote:
And I think the lines with just two || (also without text) AND the lines with more than two || in the txt-file cause problems for the script: that's where empty lines arise!
cheers for your help...it is these " | " and so the blank lines being written to the text file that have been the problem all along.
I don't know how to rid myself of them.
Posted: Wed Oct 01, 2003 8:07 am
by Derfel Cadarn
Ha, I solved another mystery!!
Good luck!
Posted: Wed Oct 01, 2003 8:17 am
by mesz

Cheers for your help - like I said thsi thing has been driving me mad for months on end.
.....
anyone else to help me?
Posted: Wed Oct 01, 2003 9:37 am
by mesz
I am stopping this thread and starting another with a rephrased question.
( at....
http://www.devnetwork.net/forums/viewto ... 2284#62284 )