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

  • Home
  • SEARCH
  • 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 6086235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:43:44+00:00 2026-05-23T11:43:44+00:00

Someone just made a group on my site which has a description with \n\r

  • 0

Someone just made a group on my site which has a description with \n\r. The thing is that I already do this to the description text:

//Convert all urls to links
$group_description = preg_replace('#([\s|^])(www)#i', '$1http://$2', $group_description);
$pattern = '#((http|https|ftp|telnet|news|gopher|file|wais):\/\/[^\s]+)#i';
$replacement = '<a href="$1" target="_blank">$1</a>';
$group_description = preg_replace($pattern, $replacement, $group_description);

$group_description = str_replace("\'" , "'", $group_description );
$group_description = nl2br($group_description);

/* Convert all E-mail matches to appropriate HTML links */
$pattern = '#([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.';
$pattern .= '[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)#i';
$replacement = '<a href="mailto:\\1">\\1</a>';
$group_description = preg_replace($pattern, $replacement, $group_description);

You can see this happening here.

You see it says there \n\r Welcome to Join.

Why didn’t it become a <br /> tag?

This is probably important, here is how I put this text into the db in the first place:

$group_description = mysql_real_escape_string($_POST['group_description']);
// And then insert the $group_description into the db without doing any more operations on it.

Any idea why I am still getting the \n\r?

  • 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-23T11:43:44+00:00Added an answer on May 23, 2026 at 11:43 am

    The problem is that the \r and \n are stored in your database as “\” “r” and “\” “\n” respectively. They’re not stored as a carriage return or new line character but the slash character followed by the letter. When you’re calling nl2br(), it’s looking for the new line character, not the textual representation of it. Hopefully that makes sense.

    You could use a regular expression (preg_replace) or str_replace to replace them. But the problem probably is caused by how the data is inserted in your database.

    For instance:

    $string = str_replace('\n', "\n", $string);
    $string = str_replace('\r', "\r", $string);
    

    You’ll notice that I used single quotes for the first one and double for the second. When using single quotes, the “\r” and “\n” are stored as text, not the special characters. That could by why they’re not stored properly in your database.

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

Sidebar

Related Questions

I have some images on my site that I made, just some .gif and
Ok, someone has just shown me a piece of PHP code and at the
How would you explain to someone who has just started programming in Java, what
I made a script for python that suggested music to someone, and was wondering
I'm new to Drupal, just made my first site and having some issues with
I just encountered this (made up code to demonstrate the problem): public ICollection<string> CreateCollection(int
just to know if someone have any idea why this bug is happening. I
I've made a voting on comments like the one this website has(something similar), and
First of all, I'll state that this is a university assignment so I'm not
I just made a Java n-tuple which is type-safe. I'm using some unconventional methods

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.