Page 1 of 1

How to remove multiple empty lines (spaces) entered by user

Posted: Mon Jan 29, 2007 11:10 am
by Tieckus
Script URL: http://gabsal.100webspace.net/testingbook/gbook.php
Version of script: 143
Hosting company: http://www.100webspace.com/
URL of phpinfo.php: http://gabsal.100webspace.net/testingbook/phpinfo.php
URL of session_test.php: http://gabsal.100webspace.net/testingbo ... n_test.php
What terms did you try when SEARCHING for a solution: spaces, multiple spaces, line breaks...

Write your message below:

Hi! I have 2 questions, (maybe they are the same):

Q1:
I would like to know if there is a way to avoid a user entering multiple empty lines. In other words: if a user enters something like this:

test







test

I would like to change it into this (turn n empty lines (spaces) into just one):

test

test

Q2:
Another problem is the following: If a user enters a lot of empty lines between words (see example here: http://gabsal.100webspace.net/testingbook/ ) Then a strange < br> tag appears and the end of the comments became bold (in the example I ONLY entered the word "test" at the first line and again the word "test" at the last line). Can that be avoided?


Thanks for your help.

[Maybe a way to avoid these problems would be to set a maximum number of characters that a user can enter in the text field, then that would refrain the user from doing this stupid input. If that is so, do you know how that can be accomplished?]

(Sorry if my questions look too naive; I am a php newbee and my mother tongue is not english!)

Posted: Mon Jan 29, 2007 3:16 pm
by Klemen
So you finally were able to login to the forum :D

Try opening gbook.php in a plain text editor (Notepad) and change lines 620 to 623 from

Code: Select all

$comments = str_replace("\r\n","<br>",$comments);
$comments = str_replace("\n","<br>",$comments);
$comments = str_replace("\r","<br>",$comments);
$comments = wordwrap($comments,$settings['max_word'],' ',1);
to this:

Code: Select all

$comments = wordwrap($comments,$settings['max_word'],' ',1);
$comments = preg_replace('/(\n|\r)+/','<br>',$comments);
Haven't really tested it so please come back and say if it worked or not.

I think I'll include this in the next version by default.

It works!

Posted: Mon Jan 29, 2007 4:15 pm
by Tieckus
It works great! Thanks a lot!
(beyond my wildest expectations :shock: )

(By the way, I was not able to log into the forum using Firefox; I managed to login at last the first time I tried with Internet Explorer)

Thank you again!