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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:25:39+00:00 2026-05-16T20:25:39+00:00

I have a php string with a lot of information to be displayed inside

  • 0

I have a php string with a lot of information to be displayed inside a textarea html element.

I don’t have access to that textarea nor to the script (if any) that generates it.

$somestring = 'first line \nSecond line \nThird line.';

$somestring as NOT been “worked” with trim or filter_var. Nothing.

On the textfield, I get the \n printed on the textarea hence, not interpreted.

What can I try in order to have those new lines applied?

Thanks in advance.

  • 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-16T20:25:40+00:00Added an answer on May 16, 2026 at 8:25 pm

    \n, \r and other backslash escape characters only works in double quotes and heredoc. In single quotes and nowdoc (the single quote version of heredoc), they are read as literal \n and \r.

    Example:

    <?php
    echo "Hello\nWorld"; // Two lines: 'Hello' and 'World'
    echo 'Hello\nWorld'; // One line: literally 'Hello\nWorld'
    echo <<<HEREDOC
    Hello\nWorld
    HEREDOC; // Same as "Hello\nWorld"
    echo <<<'NOWDOC'
    Hello\nWorld
    NOWDOC; // Same as 'Hello\nWorld' - only works in PHP 5.3.0+
    

    Read more about this behaviour in the PHP manual


    EDIT:
    The reason single and double quotes behave differently is because they are both needed in different situations.

    For instance, if you would have a string with a lot of new lines, you would use double quotes:

    echo "This\nstring\nhas\na\nlot\nof\nlines\n";
    

    But if you would use a string with a lot of backslashes, such as a file name (on Windows) or a regular expression, you would use single quotes to simplify it and avoid having unexpected problems by forgetting to escape a backslash:

    echo "C:\this\will\not\work"; // Prints a tab instead of \t and a newline instead of \n
    echo 'C:\this\would\work'; // Prints the expected string
    
    echo '/regular expression/'; // Best way to write a regular expression
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a PHP script send a XML formatted string to another
I have a string encrypted in PHP that I would like to decrypt in
What is the PHP preg_replace in C#? I have an array of string that
Say i have this PHP code: $FooBar = a string; i then need a
I have the following string in the smarty (php templating system) variable $test: <img
I have PHP configured so that magic quotes are on and register globals are
We have PHP 5.2.6 deployed to c:\php and in that folder there is the
Is there any way to have PHP automatically call a function, before a script
I have a PHP file that handles sending out confirmation emails. I also have
(Using MySQL and PHP) I have a search form that will allow my users

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.