Extra line breaks being added in form upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Extra line breaks being added in form upload

Post by mesz »

:P 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>"  ;
}
?> 
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Could we see the HTML output (a bit of the problem area)?

Mac
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post 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 )
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Hrm..maybe in a non .doc format.

Many of us here don't use Windows. :D

And opening up a .doc is, well, a painful experience.
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

of course...I forget about the feelings of you lot to windows....
give me a moment....
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

here you go -
http://www.saua.co.uk/internal/view.php( as it is not finished I have taken security away.)
User avatar
Derfel Cadarn
Forum Contributor
Posts: 193
Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany

Post 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>
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post 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...
User avatar
Derfel Cadarn
Forum Contributor
Posts: 193
Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany

Post 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!
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

the text file is just a blank text file, nothing more nothing less.
User avatar
Derfel Cadarn
Forum Contributor
Posts: 193
Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany

Post 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!
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post 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.
User avatar
Derfel Cadarn
Forum Contributor
Posts: 193
Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany

Post by Derfel Cadarn »

Ha, I solved another mystery!!
:D

Good luck!
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

:D Cheers for your help - like I said thsi thing has been driving me mad for months on end.

.....
anyone else to help me?
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

I am stopping this thread and starting another with a rephrased question.
( at....
http://www.devnetwork.net/forums/viewto ... 2284#62284 )
Post Reply