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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:41:17+00:00 2026-06-06T21:41:17+00:00

First, I’d like to apologize, I’m still a beginner. For learning purposes I’m creating

  • 0

First, I’d like to apologize, I’m still a beginner.

For learning purposes I’m creating a blog engine and I just noticed that when I list the comments, escaped characters like carriage return (pressing enter) are shown in the database correctly, but only a whitespace character when displaying the comments.

I’m using PostgreSQL 8.3.

Here you can see an example database entry:

fema=> select * from comments where id = 54;
-[ RECORD 1 ]-------------------------
id       | 54
authorid | 1
text     | This new line won't show.\r
        : No\r
        : \r
        : new\r
        : \r
        : \r
        : \r
        : lines.
time     | 1341417673
postid   | 15
answerid | 0

Here you can see what var_dump() shows:

string(50) "This new line won't show. No new lines." 

This is how I’m getting the data:

$stmt = db::$db->prepare("select comments.id as commentid ,authorid,text,time,postid,answerid,users.* from comments left join users on users.id = comments.authorId where postid = :postId");
            $stmt->execute(array('postId' => $_GET['p']));
        $commentRslt = $stmt->fetchAll();

Then foreach to iterate through them and replace the mark I’m using to identify things I have to replace:

$currComment = str_replace('{{{cms:comment:text}}}', $commentRslt[$key]['text'], $currComment);

This is how I insert the new comment to the DB:

$stmt = self::$db->prepare('INSERT INTO comments (authorId, text, time, postId, answerId) VALUES (:authorId, :text, :time, :postId, :answerId)');
$stmt->execute(array(   'authorId' => $_SESSION['userId'],
                        'text' => str_replace(array('<','>'), array('&lt','&gt'), isset($_POST['newCommentArea']) ? $_POST['newCommentArea'] : $_SESSION['newCommentArea']),
                        'time' => time(),
                        'postId' => isset($_POST['commentNew']) ? $_POST['commentNew' ] : $_SESSION['postId'],
                        'answerId' => $answerId));

Sorry for the many code samples, but I don’t even know where the problem is and I wanted to be thorough.

So could anyone please tell me how to solve the problem? If only just by telling me where I made the mistake. I really have no clue.

Thanks.

  • 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-06-06T21:41:19+00:00Added an answer on June 6, 2026 at 9:41 pm

    Jut guessing here, but:

    Consecutive whitespace is collapsed to a single space by HTML/the browser. Replace newlines with <br> tags if you want to keep them, using nl2br.

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

Sidebar

Related Questions

First, I have a list of QWidget s that I won't know the length
First, I'd like to thank anyone that can get me through this in advance.
First, I want to let everyone know that I am using an aspx engine
First i selected images from photo library to ALAsset Library and after that i
I've got a string that has curly quotes in it. I'd like to replace
First of all, some background: I'm trying to get in a list of integers
First, I am a SQL noob, second if there is a better solution that
First, my question might sound like a duplicate, but I have been going through
First off I have an app that provides the user information about the amount
First of all, I just installed XE2 for the first time, and plan to

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.