mydarkpassenger Posted May 26, 2010 Share Posted May 26, 2010 I'm trying to input my string into a textarea however, newline characters don't seem to be splitting the data over multiple lines. They do echo out into the textarea. I read you need to use breaks with textareas and people suggest the nl2br function to convert newline characters to <br /> statements, however I notice when I use <br /> in my string they also just echo out in the textarea but don't do anything. Am I missing anything. Here's a sample: <textarea cols="200" rows="20"> <? $text = ""; $text .= '[HIDE]\n'; $text .='File Name: ' . $nzb->getName() .'\n'; $text .='Poster: ' . $nzb->getPoster() .'\n'; $text .='Post Date: '. $nzb->getPostedDate() .'\n'; $text .='Group:' . implode(',', $nzb->getGroups()) . '\n'; $text .='File Size: ' . $size . 'MB' . '\n'; $text .= '\n'; $text .='Search: Engines'; $text .='Binsearch\n'; $text .='Newzleech\n'; $text .='NZBIndex\n'; $text .='NZBClub\n'; $text .='Yabsearch\n'; $text .='[/HIDE]\n'; echo nl2br($text); ?> </textarea> What's wrong with my code? Quote Link to comment https://forums.phpfreaks.com/topic/203014-how-do-you-use-newlines-with-textareas-and-php/ Share on other sites More sharing options...
Alex Posted May 26, 2010 Share Posted May 26, 2010 The problem is that you're using single quotes which will take the string literally, and not take \n as a new line character. Instead use double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/203014-how-do-you-use-newlines-with-textareas-and-php/#findComment-1063814 Share on other sites More sharing options...
mydarkpassenger Posted May 26, 2010 Author Share Posted May 26, 2010 Thank you I didn't even think about it. Quote Link to comment https://forums.phpfreaks.com/topic/203014-how-do-you-use-newlines-with-textareas-and-php/#findComment-1063817 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.