paulmason411 0 Report post Posted December 7, 2007 Hi guys,I have set up a form with a textarea. If I have text on multiple lines such as: here is some contenthere is some more content then when I print it out as html it will be returned on one line like so: here is some contenthere is some more content When i look at the content in the database it looks just like the original way i entered it (contains the multiple lines).Is there a function in php so that when i spit it out in html it retains the multiple line format?Thanks in advance. Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted December 7, 2007 try this: $value = str_replace(array( "\r", "\n", "%0a", "%0d"), ' ', $value); Share this post Link to post Share on other sites
mahirharoon 0 Report post Posted December 7, 2007 put \n at last of the line Share this post Link to post Share on other sites
paulmason411 0 Report post Posted December 7, 2007 jlhaslip you've done it again. Thanks! Share this post Link to post Share on other sites
ewcreators 0 Report post Posted December 7, 2007 jlhaslip you've done it again. Thanks!that may be sorta complex. The easiest way is to use :<?php$line_break=nl2br($_POST['text']);echo $line;?>nl2br() is a function which inserts a <br /> automatically at the end of every line. Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted December 7, 2007 $value = str_replace(array( "\r", "\n", "%0a", "%0d"), ' ', $value);I use that in a function that replaces all the bad stuff in Emails, Comments, $_POST arrays, etc. Yes, probably a little overkill checking for the hex values. And you are correct, the nl2br() would likely do it.I had not had my morning coffee yet when I replied... Share this post Link to post Share on other sites
iGuest 3 Report post Posted June 22, 2008 character count Converting Textarea Return Characters To Guys teach me how to post the character count on php from the html textarea. I know how to do the wordcount but the character count is really my problem Need help -reply by abby Share this post Link to post Share on other sites
who? 0 Report post Posted July 9, 2008 (edited) character count Converting Textarea Return Characters To Guys teach me how to post the character count on php from the html textarea. I know how to do the wordcount but the character count is really my problem Need help -reply by abby I'm not sure if I understand your problem, but try using strlen($str), where $str is the textarea value. Edited July 9, 2008 by who? (see edit history) Share this post Link to post Share on other sites
optiplex 0 Report post Posted July 21, 2008 (edited) Oh thats really simple!you can replace newlines using str_replacelike this $your_string = str_replace(array(chr(10), chr(13)), "<br />", $your_string); or you can use nl2br$your_string = nl2br($your_string); BUT if you are showing html code anyway, you can write it in a textarealike : <textarea><? echo $your_string; ?></textarea>or using the <PRE> tag, like this:<PRE><? echo $your_string; ?></PRE>But there are more options afcourseThats it!- optiplex Edited July 21, 2008 by optiplex (see edit history) Share this post Link to post Share on other sites
gogoily 0 Report post Posted August 4, 2008 There's a very useful function in PHP to handle this situation. The function is "nl2br()", try it and you'll find how cute PHP is Share this post Link to post Share on other sites