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...

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.