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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:33:17+00:00 2026-05-25T02:33:17+00:00

I use php to create a file that can be donwloaded when pressing a

  • 0

I use php to create a file that can be donwloaded when pressing a link.

Many variations of code has been tried. No reason this one should not work:

$output = 'test    spaces, test 
enter, test n, \ntest nr, \n\rtest nt, \n\ttest html-br, <br /><br>end of line';
$output .= '\r\n';
$output .= 'blahblah';
header('Content-type: text/plain');
header('Content-Disposition: attachment;filename="'.$filename.'.txt"');
print $output;
exit;

But the file that is returned starts with two spaces that I did not insert. No linebreaks on \r\n.

If I open the file in notepad++ I do get a linebreak on the ‘enter’
In ordinary notepad that break is not even there. Output in downloaded text file is like this between quotes:

  In notepad++
  "  test    spaces, test 
  enter, test n, \ntest nr, \n\rtest nt, \n\ttest html-br, <br /><br>end of line\r\nblahblah"

So. What am I doing wrong? Outputting something before the header, so the header is not working?

UPDATE: Thanks for the help. Two right answer at the exact same time. First answer when ordered “oldest first” got marked as right answer. Using single quotes solved the issue.

The issue with the two empty spaces in the beginning of the output is not related to the code/php in the example given. It is an artifact from the framework that is used.

  • 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-25T02:33:18+00:00Added an answer on May 25, 2026 at 2:33 am

    Newlines (using \n & \r) are only recognized in double quotes, not in single quotes.

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

Sidebar

Related Questions

I'm trying to use PHP to create a file, but it isn't working. I
I am looking for a PHP class that can parse an ICalendar (ICS) file
I tried to create a htaccess file that rewrites, for example the URL from
I want to use php in console mode and create an environment to test
Is it possible to use PHP's SimpleXML functions to create an XML object from
We use the ExpressionEngine CMS (php) to create websites. For each site, we set
I used to use procedural-style PHP. Later, I used to create some classes. Later,
One significant drawback of CSS is that one can't use variables. For example, I'd
Is there any alternative to file_get_contents that would create the file if it did
I would like to use an xml file to create a html email. I

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.