kaliok Posted May 28, 2007 Share Posted May 28, 2007 Hi I am having some trouble with converting html code to real line breaks in a textarea, I have the following code that I gets html code from a database and then puts it into a textarea but the str_replace I am using converts the text but puts the actual characters \r\n in the textarea, and doesn't actually turn it into a linebreak. (the br below is reality in triangular brackets!) $paragraph=$row['paragraph']; $paragraph=str_replace('br','\r\n',$paragraph); ..... <textarea name="ud_text" cols="50" rows="15" maxlength="300"><? echo $paragraph ?></textarea> Perhaps someone can help me with this? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/53308-line-breaks/ Share on other sites More sharing options...
pocobueno1388 Posted May 28, 2007 Share Posted May 28, 2007 I think your looking for the function nl2br(). http://www.php.net/manual/en/function.nl2br.php Quote Link to comment https://forums.phpfreaks.com/topic/53308-line-breaks/#findComment-263447 Share on other sites More sharing options...
wildteen88 Posted May 28, 2007 Share Posted May 28, 2007 Use double quotes when using escaped characters in a string.: $paragraph=$row['paragraph']; $paragraph=str_replace('<br />',"\r\n",$paragraph); But can I ask why you are converting html line breaks back into newlines? Quote Link to comment https://forums.phpfreaks.com/topic/53308-line-breaks/#findComment-263486 Share on other sites More sharing options...
kaliok Posted May 29, 2007 Author Share Posted May 29, 2007 Guess I was being a little thick. Couldn't get nl2br to work, was using it in the wrong place, needed to put in after getting it from the database! So I converted the carriage returns/line breaks to a my own bracketed chars, then converted them on the front end, but wasn't behaving in the text area, so it prompted the question. Got the point now! Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/53308-line-breaks/#findComment-263581 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.