Page 1 of 1

How to remove a blank line in a form

Posted: Fri Oct 20, 2006 11:17 pm
by tarja311
Hello all,

I hope i am posting in the right place. I have built a search engine and it has a basic form in place where users type in some text and it is sent and stored on the database for later retrieval via search.

Now my problem lies in the submission of the text. Usually the users copy / paste their text into the form and that sometimes leaves a bunch of blank spaces in between the lines of text. Example :

this is some text...

this is some more text...

As you can clearly see, there is a blank line in between the two lines of text. This also happens if the user hits enter before they copy /paste, and it leaves an empty line above the text.

Is there a way i can remove this before it is sent off to the database? because when this stuff is searched, the blank lines are stored as well. There are not supposed to be any empty lines like this.

I am running Windows XP. MySQL and PHP 5

Thanks

-- tarja

Posted: Fri Oct 20, 2006 11:26 pm
by akimm
trim() function is probably worth looking at on php.net

Posted: Sat Oct 21, 2006 1:00 am
by tarja311
Hi,

Actually i've been trying to use trim for the last three hours or so. I've looked up the examples on php.net and read the comments below that, i've even googled it, but so far i have not found an example as to how you can remove a blank space that does not contain any characters off the html form.

EDIT :

Nevermind, i've solved it. Instead of fighting with it on the PHP side, i had the database check for it instead.

Code: Select all

if($file == ""){ $sql = "DELETE FROM ....

Posted: Sat Oct 21, 2006 2:05 am
by akimm
Ok, good. Trim should remove whitespaces though..

Posted: Sat Oct 21, 2006 5:02 pm
by John Cartwright
akimm wrote:Ok, good. Trim should remove whitespaces though..
Please read the function description
trim -- Strip whitespace (or other characters) from the beginning and end of a string
What you want to do is a str_replace() for newline characters.