sintax63 Posted January 26, 2010 Share Posted January 26, 2010 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 https://forums.phpfreaks.com/topic/189895-auto-insert-line-breaks-in-text-area-issue/ Share on other sites More sharing options...
schilly Posted January 26, 2010 Share Posted January 26, 2010 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 https://forums.phpfreaks.com/topic/189895-auto-insert-line-breaks-in-text-area-issue/#findComment-1002006 Share on other sites More sharing options...
sintax63 Posted January 26, 2010 Author Share Posted January 26, 2010 Oh, that sounds perfect! I will have to find a tutorial on find / replace so I can figure out how to do that. Thanks for the tip. Link to comment https://forums.phpfreaks.com/topic/189895-auto-insert-line-breaks-in-text-area-issue/#findComment-1002011 Share on other sites More sharing options...
jl5501 Posted January 26, 2010 Share Posted January 26, 2010 Consider the page in the manual for the str_replace() function Link to comment https://forums.phpfreaks.com/topic/189895-auto-insert-line-breaks-in-text-area-issue/#findComment-1002014 Share on other sites More sharing options...
sintax63 Posted January 26, 2010 Author Share Posted January 26, 2010 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 https://forums.phpfreaks.com/topic/189895-auto-insert-line-breaks-in-text-area-issue/#findComment-1002031 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.