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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:39:59+00:00 2026-06-05T04:39:59+00:00

I want to do an ASCII text download of user-selected SQL data, that can

  • 0

I want to do an ASCII text download of user-selected SQL data, that can be opened immediately in notepad. DB connection works fine, as do “header” commands to initiate download, but I’ll be damned if I can get the end-of-line characters to show up properly.

The header is statically defined via:

$header = <<<EOD
  #Some header information
  #goes here on multiple
  #lines
  EOD;

with each row data being concatenated with tabs:

$RS_SQL = $DBinterface->dbGetRecordSet($someQuery);
foreach($RS_SQL as $row) {
  $rowdata = '';
  foreach($row as $key=>$val) {
    if((!(int)$key) && $key!='0') {
      $rowdata[] = $row[$key];
    }
  }
  $dataOutput.=implode("\t",$rowdata)."\n";
}
header("Content-type: text/plain; charset=ISO-8859-1");
header("Content-Disposition: attachment; filename=SQLDataExport.txt");
echo $header."\n".$dataOutput;

Header shows up in notepad fine, and all the tab spacing is exactly as designed… However, any attempt to format rows nicely via \r or \n characters result in a single line with unknown characters (square boxes) where the linefeeds should be.

I’ve tried writing the file to the server, then reading the stream and outputting; tried variations on the header information… Kinda get the idea that there’s something odd with the way the page is being downloaded to the browser via binary, but?

What am I missing?

Many thanks.

  • 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-06-05T04:40:01+00:00Added an answer on June 5, 2026 at 4:40 am

    Instead of using “\n” or “\r\n”, use PHP_EOL for this. It handles any cross platform issues and is good for writing files that are meant to be saved on the server or client.

    This question has some information and could be considered related to what you are trying to do.

    You would use it like so:

    $RS_SQL = $DBinterface->dbGetRecordSet($someQuery);
    foreach($RS_SQL as $row) {
      $rowdata = '';
      foreach($row as $key=>$val) {
        if((!(int)$key) && $key!='0') {
          $rowdata[] = $row[$key];
        }
      }
      $dataOutput.=implode("\t",$rowdata).PHP_EOL;
    }
    header("Content-type: text/plain; charset=ISO-8859-1");
    header("Content-Disposition: attachment; filename=SQLDataExport.txt");
    echo $header."\n".$dataOutput;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a string in JavaScript that contains all ascii characters. How
I have Uitable with data read from a AScii file. I want to select
How can I decode a hex string to an ascii string? I want to
I want to remove rectangles etc that enclose text in a screenshot image, so
I have an HTML (left-to-right) text element that I want to overflow to the
I have a file that contains Unicode text in an unstated encoding. I want
I want to make an identical sha512 in C# and mysql. c# System.Security.Cryptography.SHA512.Create().ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(test)); C#
I am writing a .NET application that can communicate with HID devices. I want
I have an ASCII text file. I want to read the file, line by
I have some auto-generated text that includes non-ascii encoded parentheses. For example: <div> Some

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.