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

Dr. GBooky is here to help you with your guestbook problems ...
Post Reply
Tieckus
Posts: 4
Joined: Mon Jan 29, 2007 12:06 am

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

Post 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!)
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post 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.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Tieckus
Posts: 4
Joined: Mon Jan 29, 2007 12:06 am

It works!

Post 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!
Post Reply