Jump to content

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


cooldude832

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.