Jump to content

[SOLVED] Carriage returns in a Textarea to <br />??


cooldude832

Recommended Posts

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

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.

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.