Jump to content

MSSQL + \n\r


jt

Recommended Posts

I have a form that includes a text area.  When I insert the value of the text area into MS SQL, it places \r\n etc wherever the user wanted a new line or paragraph.

 

So for example, in the form, my text looks like this:

 

test

testtest

test

 

in the column in SQL Server, my inserted value looks like:

 

test\r\n\r\ntesttest\r\n\r\ntest

 

etc

 

I need this to insert into SQL server, without those values (basically, I just want to insert exactly as it looks on the textfield when the user fills it in).  In MySQL, I have no problem with this since it seems to insert normally (although I think PHPMyAdmin might format those fields with nl2br() automatically, not sure about that).  Then, when I display these from a SELECT on my site, I need to be able to use the nl2br() function normally so that the text gets formatted for display.

 

I tried using a couple different forms of preg_replace(), but can't seem to get that right, not does str_replace() seem to do what I want.

 

I've searched and searched for something on this, and can't seem to get what I'm looking for.

 

Any thoughts would be much appreciated.

 

 

Link to comment
Share on other sites

Nevermind, I was passing the string through a deprecated custom function that was using the function mysql_real_escape_string() before it was being inserted.  Removing this and using a stripslashes() on the string before insert works the way I intend.

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.