Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textarea tags

Status
Not open for further replies.

Valcor

IS-IT--Management
Mar 22, 2001
25
US
Hi All,
I have MySQL database that is storing address details of users, and instead of trying to work out how many fields each user is going to need for their address, I was just going to use a textarea tag for the input. This happily passes the data to the MySQL database, and stores it as it is displayed in the textarea box. The problem I have is when trying to retrieve the data, it removes all the carrage returns. For example:

How it appears in the textarea box (also appears in mysql like this too:
-----------------------------------
My Address
My Road
My Town

How it is returned back to HTML on a SELECT function:
-----------------------------------------------------
My Address My Road My Town


Is there any way to correct that?
Jon
 
In HTML, carrage returns are only defided by a tags such as &quot;<BR>&quot;. Even if there is a line break in the text the browser will not break unless a tags says so.

You could possibly correct this by using the nl2br() function.

I would probably go back and look how you store the data though. In most of the databases that I have put together, we store the data:
AddressLine1
AddressLine2
AddressLine3
City
State
Zip

But we also dont do anything with addresses outside the USA (yet), so I am not positive if this format would constrain you to holding just US addresses.
 
The data you enter in the database should look like this:

My Address<br>My Road<br>My Town<br>

Then it shouldn't be any problem to show it on your page

I'm not sure if it would work in textareas, if not, try

My Address\nMy Road\nMy Town\n
 
There is a nifty little function in PHP to take care of this very problem: nl2br($your_string)

see
This takes newlines (carriage returns) and converts them to HTML <br> tags. You can do this upon insert into the database, but then you will have the pain of removing them if you want to output the data to a <textarea> or any other format. better to just use nl2br() upon output from the database to your web page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top