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

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.