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 have a PHP script that does basic encryption of a string through the
I have a string that I want to have PHP read as a piece
I'm pretty new to PHP and have a String which contains an HTML page.
I'm still learning a lot about PHP and string alteration is something that is
I have a simple PHP function that outputs HTML. <?php function get_header() { ?>
Possible Duplicate: remove duplicate from string in PHP Have a string like: $str =
I have an url like this: http://www.w3schools.com/PHP/func_string_str_split.asp I want to split that url to
I have a string in PHP and I want it to match the regex
In PHP i have this string variable: $var = 00480722 ZF452D041502 13 9900 153370178;
Hello I have a string in PHP $string = ...................blah blah blah.................. where the

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.