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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:16:24+00:00 2026-05-23T16:16:24+00:00

There is a user textarea input. I need to remove all new lines before

  • 0

There is a user textarea input. I need to remove all new lines before saving (so it should be only one line).

I use

$text = str_replace("\r\n", "", $text);
$text = str_replace("\n", "", $text);

for this.

But one user entered text, that has new line, and it cannot be removed with that code.
I also tried \r\n and \r with no result.

I cannot copy it here, because as soon as I copy it, new line will be replaced with standard \n.

How can I remove this new line? Or how can I see what its character is?
It is saved in MySQL now.

  • 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-23T16:16:24+00:00Added an answer on May 23, 2026 at 4:16 pm

    Have you tried:

    • RTRIM http://php.net/manual/en/function.rtrim.php : rtrim — Strip whitespace (or other characters) from the end of a string
    • TRIM http://php.net/manual/en/function.trim.php : trim — Strip whitespace (or other characters) from the beginning and end of a string

    After clarification

    // Order of replacement
    $str     = "Line 1\nLine 2\rLine 3\r\nLine 4\n";
    $order   = array("\r\n", "\n", "\r");
    $replace = '';
    
    // Processes \r\n's first so they aren't converted twice.
    $newstr = str_replace($order, $replace, $str);
    

    This is direct from the PHP manual: http://php.net/manual/en/function.str-replace.php

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

Sidebar

Related Questions

I am using HTML textarea for user to input some data and save that
I'm creating comment fields which are based on user input into textarea. But when
I have a page in which there are a few textarea and <input type=text>
I'm populating a textarea with previous input of a user. This is pulled from
In my application there are few <textarea> presents and applied pagination to all these
I want to make a site where there user can basically navigate the web
Is there a user-management plugin for grails? Nearly every website requires things like: Users
Context: There's an application where you draw things on canvas. Where user clicks there's
i have this MySQL statement from a search page, the user enters there postcode
I have an ascx component, that holds two-level menu, because there are several user

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.