Jump to content

Auto Insert Line Breaks In Text Area Issue


sintax63

Recommended Posts

I have a textarea on my site that people can obviously enter text into that gets inserted into my database. In trying to find a way to automatically detect paragraphs / line breaks I found this snippet of code:

 

$ud_history = nl2br($ud_history);

 

This seems to work just fine as two paragraphs of text contain two line breaks in between them.

 

...end of first paragraph. <br />
<br /> 
Beginning of second paragraph.

 

Now the problem comes in when they are adding to this information. I pull the chunk of text out of the database and put it back into the textarea for them to update. This text already contains the two line breaks. However, if they edit the information and send it back into the database, two more lines breaks are added between each paragraph.

 

...end of first paragraph. <br /><br /> 
<br /><br />
Beginning of second paragraph.

 

This obviously is creating display issues when the text gets spit out on an actual web page as there are now four empty spaces between each paragraph.

 

Is there anyway around this or am I going about the execution all wrong?

 

Thanks in advance...

well when you put it back in the textarea you don't want to display the <br /> tags to the user. just do a find replace when it goes into the textarea to change the <br /> back to \n then when they submit the form again run nl2br again.

 

that make sense?

Well I decided, since my site was so new and there weren't a lot of records, to insert the data into the table clean, and then use the nl2br() function to output the data correctly. That way my tables would be easier to read and the website still looked as intended.

 

Thanks for the help everyone!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.