Cory94bailly Posted February 28, 2009 Share Posted February 28, 2009 I have a textbox on my site and if I enter something like this: test test2 It will format to this: test test2 How can I detect if there is a line break without there actually being one (\n or <br>) and possibly add one? Quote Link to comment https://forums.phpfreaks.com/topic/147358-detect-line-break-in-a-html-textbox/ Share on other sites More sharing options...
napurist Posted February 28, 2009 Share Posted February 28, 2009 Add the wrap attribute to the html tag like this... <textarea cols="20" rows="5" wrap="hard"> Quote Link to comment https://forums.phpfreaks.com/topic/147358-detect-line-break-in-a-html-textbox/#findComment-773483 Share on other sites More sharing options...
premiso Posted February 28, 2009 Share Posted February 28, 2009 The \n character is there. To detect it you can use strstr But have no doubt it is there, use nl2br before you output the test to see it (that converts \n to <br>) so it is visible to html. EDIT: A note though, if you used spaces instead of enters, it could display like that. So instead of \n it is just a bunch of spaces. Quote Link to comment https://forums.phpfreaks.com/topic/147358-detect-line-break-in-a-html-textbox/#findComment-773484 Share on other sites More sharing options...
Cory94bailly Posted February 28, 2009 Author Share Posted February 28, 2009 Add the wrap attribute to the html tag like this... <textarea cols="20" rows="5" wrap="hard"> Tried, didn't work. The \n character is there. To detect it you can use strstr But have no doubt it is there, use nl2br before you output the test to see it (that converts \n to <br>) so it is visible to html. EDIT: A note though, if you used spaces instead of enters, it could display like that. So instead of \n it is just a bunch of spaces. I checked in my mysql table and it did not show anything but the stuff with no <br>s or \n s. Quote Link to comment https://forums.phpfreaks.com/topic/147358-detect-line-break-in-a-html-textbox/#findComment-773496 Share on other sites More sharing options...
premiso Posted February 28, 2009 Share Posted February 28, 2009 MySQL should not show it. When you output the data, do the nl2br. It should convert it. Line breaks are escaped characters. They are not suppose to display, if you view the source of the html file you should notice the breaks. Quote Link to comment https://forums.phpfreaks.com/topic/147358-detect-line-break-in-a-html-textbox/#findComment-773497 Share on other sites More sharing options...
Cory94bailly Posted February 28, 2009 Author Share Posted February 28, 2009 MySQL should not show it. When you output the data, do the nl2br. It should convert it. Line breaks are escaped characters. They are not suppose to display, if you view the source of the html file you should notice the breaks. I echoed this out: $body = nl2br($news['news_body']); And it just showed nothing.. Quote Link to comment https://forums.phpfreaks.com/topic/147358-detect-line-break-in-a-html-textbox/#findComment-773511 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.