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 340297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:36:11+00:00 2026-05-12T10:36:11+00:00

How can you preserve enters given by the user in the database and show

  • 0

How can you preserve “enters” given by the user in the database and show them then to other users?

I store the question of the user and use the following functions to sanitize the user data, prepare it, and execute the SQL command, respectively.

 pg_escape_string
 pg_prepare
 pg_execute

I use htmlentities with ENT_QUOTES to convert the data HTML.
This procedure removes all enters, apparently in the form \n, in the question.

I would like to have a similar question-system as in SO: to show only double enters to users as line breaks.

  • 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-12T10:36:11+00:00Added an answer on May 12, 2026 at 10:36 am

    After you call htmlentities(), call nl2br(). The web browser ignores plain newline characters so you need to convert them to <br /> elements to make them show up.

    nl2br — Inserts HTML line breaks before all newlines in a string

    Description

    string nl2br ( string $string [, bool $is_xhtml= true ] )
    Returns string with <br /> or <br> inserted before all newlines.

    For example:

    echo nl2br(htmlentities($input));
    

    To only show double newlines and ignore single ones, you could instead use a more sophisticated string replacement function, preg_replace:

    echo preg_replace('/\n\s*\n/', "<br />\n<br />\n", htmlentities($input));
    

    Here '/\n\s*\n/' matches a newline, followed by any amount of whitespace, followed by another newline. It replaces any such substring with two <br /> elements. Single newlines are ignored. It’s also nice because it’ll ignore extraneous spaces and tabs that are invisible, such as if a user typed this:

    This is a paragraph.\n
    It is pretty short.\n
    <space><tab>\n
    Here’s another paragraph.\n
    It too is short.

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

Sidebar

Related Questions

How can I preserve the states of checkbox using session? I tried the following
Can I order my users in the database, so I don't have to say
When using 'db_table' to explicitly set the database table name, how can you preserve
I want to preserve Ripple effect on my UIImageView. I know we can animate
How can I preserve the order in which the hash elements were added FOR
After merging 2 LINQ lists, how can I preserve the table objects and names?
Is there a way i can preserve\r\n on XElement.Load(). TextReader reader = new StringReader(rawInputString);//rawInputString
I recently came across a Microsoft Interview Question for Software Engineer. Given an array
In my application I have places where users can send messages and leave comments
In my iPhone app I have a settings page where a user can enter

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.