0

I have a lot of MySQL string content that has many instances of "\n" in it. I know that if I'm dealing with strings directly, the "\n" is only interpreted as a line break if I have double quotes around it. However, when the strings come out of the database, they're interpreted literally (the '\n' stays as is). Obviously I can do my own str_replace(), but is there a simple way to treat values from mySQL as if they were double-quote-enclosed strings?

jaydisc
  • 369
  • 2
  • 11
  • http://stackoverflow.com/questions/5241748/php-convert-single-quoted-string-to-double-quoted – Trey Sep 29 '14 at 05:40
  • 1
    reads like the data is going in to the db incorrectly. –  Sep 29 '14 at 05:50
  • 1
    `stripcslashes()` does that (and a bit more). But you may still want to fix your prior database population woes. – mario Sep 29 '14 at 05:54
  • The data is Markdown text being imported from CSV files where editors have used \n instead of line breaks as the line breaks are misinterpreted as some unknown character. – jaydisc Sep 29 '14 at 06:00

1 Answers1

0

While inserting string data in db I prefer to use addslashes() functions. With this my data is inserted correctly in MySQL format. Also when showing the data on front-end, I use stripslashes(). You can always refer PHP manual for more info on this functions.