cooldude832 Posted October 31, 2007 Share Posted October 31, 2007 I tried doind a nl2br() on my textarea, but the spacing failed to work any idea maybe a str_replace("\r","<br />",$string); ?? Link to comment https://forums.phpfreaks.com/topic/75432-solved-carriage-returns-in-a-textarea-to/ Share on other sites More sharing options...
teng84 Posted October 31, 2007 Share Posted October 31, 2007 can you explain it a little bit more Link to comment https://forums.phpfreaks.com/topic/75432-solved-carriage-returns-in-a-textarea-to/#findComment-381593 Share on other sites More sharing options...
cooldude832 Posted October 31, 2007 Author Share Posted October 31, 2007 when you type in a textarea like posting message, I want the spaces to be relavent as they are here in my example of typing in this $bio = mysql_real_escape_string(bb2html((stripslashes(strip_tags(trim($_POST['Bio']))))); they aren't relative Link to comment https://forums.phpfreaks.com/topic/75432-solved-carriage-returns-in-a-textarea-to/#findComment-381594 Share on other sites More sharing options...
trq Posted October 31, 2007 Share Posted October 31, 2007 Simply use nl2br when you display the data. Not on the way in to the database. Link to comment https://forums.phpfreaks.com/topic/75432-solved-carriage-returns-in-a-textarea-to/#findComment-381596 Share on other sites More sharing options...
hitman6003 Posted October 31, 2007 Share Posted October 31, 2007 If you want to preserve the spacing at the beginning of a line, you'll have to wrap the string in pre tags, or replace the spaces with ... $string = "this is a string with random spacing"; echo "This is the unadulterated string: <br />" . $string . "<br /><br />"; echo "This is the string with pre tags:<pre>" . $string . "</pre><br /><br />""; echo "This is the string without pre tags, but with formatting: " . nl2br(str_replace(" ", " ", $string)); Remember that unless you use a monospace font (e.g. Courier New) the characters won't line up. Link to comment https://forums.phpfreaks.com/topic/75432-solved-carriage-returns-in-a-textarea-to/#findComment-381598 Share on other sites More sharing options...
cooldude832 Posted October 31, 2007 Author Share Posted October 31, 2007 Simply use nl2br when you display the data. Not on the way in to the database. I did this on the output no good my input looks line Line 1 Some stuff..... Line2 Some stuff.... Line 3 Some stuff. But on output using $bio = nl2br($row['Bio']); echo $bio; it is Line 1 Some stuff.....Line2 Some stuff....Line 3 Some stuff. I use $bio = mysql_real_escape_string(bb2html(stripslashes(strip_tags(trim($_POST['Bio']))))); on it going in, and coming back into the <textarea> it looks fine with the breaklines, but outputted no. So I know my bbcode ain't kill it. Link to comment https://forums.phpfreaks.com/topic/75432-solved-carriage-returns-in-a-textarea-to/#findComment-381600 Share on other sites More sharing options...
teng84 Posted October 31, 2007 Share Posted October 31, 2007 but outputted no. So I know my bbcode ain't kill it. it ain't kill your nl2br but ? then i guess that is not working try to replace bb2html with nl2br AND surely it will work Link to comment https://forums.phpfreaks.com/topic/75432-solved-carriage-returns-in-a-textarea-to/#findComment-381603 Share on other sites More sharing options...
cooldude832 Posted October 31, 2007 Author Share Posted October 31, 2007 I hadn't verified any of the data and what I found out through looking closer was that data had some funky spacing to it. so it really wasn't a line break in it, but actually some idiot holding down the space bar. I think what was happening was the browsers were not reading the extra spaces and thus decided to nuke em out. So now I got 150 profiles to sanitize fun However I will note I tested some returns and the nl2br() on output worked fine. Link to comment https://forums.phpfreaks.com/topic/75432-solved-carriage-returns-in-a-textarea-to/#findComment-381604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.