Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6629065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:12:25+00:00 2026-05-25T22:12:25+00:00

I have a MySQL table with 2 columns: text : stores a multi-line text

  • 0

I have a MySQL table with 2 columns:

  1. text: stores a multi-line text which could have line breaks as \n, \r, \r\n.... The text is inserted via a webform and could have been inserted by any browser on any OS.

  2. line_break: represents what type of line break this particular text will use (could be \n, <br>, <br />, …). This is also inserted via a webform by a user.

In PHP I then do the replacement:

$text = preg_replace ("/(\r\n|\r|\n)/", $row['line_break'], $row['text']);

Interestingly, if the line break is stored in the DB as \n I will actually show \n instead of the newline. On the other hand, the following regexp will work correctly:

$text = preg_replace ("/(\r\n|\r|\n)/", "\n", $row['text']);

How do I need to store the newline in the DB for it to “work” correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:12:25+00:00Added an answer on May 25, 2026 at 10:12 pm

    In php, "\n" is a special notation for writing that special character that means ‘line break’. But if you store the actual text \n in your database, you have just that text, and not the line break character. You have what you get when you write '\n' or "\\n" in PHP. Make sure you store the actual line break character in your database and not the literal \n text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL InnoDB table with 238 columns. 56 of them are TEXT
if i have a table which has columns with fixed lenght, Will mySQL count
I have this code for print a multi columns table from mysql $k=<table width='100%'
I have a legacy MySQL table called lnk_lists_addresses with columns list_id and address_id .
I have multiple columns in a mySQL table. Three of the columns are named
I have mysql table that has a column that stores xml as a string.
I have a Mysql table where it combines three tables. This table stores some
I have a MySQL database and a table which has a names column as
I have a legacy mysql database and there's this table which has a few
I have a table in mysql: ( _table ) with a a few columns,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.