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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:02:54+00:00 2026-06-04T02:02:54+00:00

We have manage to export data from our mysql table into a .txt file.

  • 0

We have manage to export data from our mysql table into a .txt file. The problem now when view it with wordpad is nice. But with notepad or even microsoft word it looks bad the \n is not working well as in notepad all of it on same line did not respect the \n. What should I add? Below is our codes.

<?php
require_once('config.php');     
// If the checkbox values are meant to all be integers, you might want to perform some validation/sanitisation/filtering here     
// Up to you to do that      // Collapse the IDs from the checkboxes into a comma-delimited string     
$link = mysql_connect(dbHost, dbUser, dbPassword);
if(!$link)
    {
            die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(dbDatabase);
    if(!$db) 
    {
            die("Unable to select database");
    }     
// Template the SQL Query     
$sqlStr = 'SELECT stringData,dataInsertDateTime  FROM tblData  WHERE aID=1965';     
// Compile the SQL Query String     
//$sqlStr = sprintf( $sqlTpl , $export_ids );      
// Execute the SQL Query     
if( !( $sqlRes = mysql_query( $sqlStr ) ) )
{      
 // SQL Error - Log it, Handle it     
}
elseif( mysql_num_rows( $sqlRes )==0) 
{       // No Rows Returned - Log it, Handle it     
}
else
{       // We have results - process them       
$text = array();       
while( $r = mysql_fetch_assoc( $sqlRes ) )
{         // Looping through the returned rows, adding them to the $text array         
$text[] = $r['stringData']."  ".$r['dataInsertDateTime'];       
}       
// Collapse the $text array down into a normal string, with one element per line       
$output = implode( "\n" , $text );        
// Output Handling from @narcisradu's answer       
header("Pragma: public");       
header("Expires: 0");       
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");       
header("Cache-Control: private",false);       
header("Content-Transfer-Encoding: binary;\n");       
header("Content-Disposition: attachment;filename=\"filename.txt\";\n");       
header("Content-Type: application/force-download");       
header("Content-Type: application/octet-stream");       
header("Content-Type: application/download");       
header("Content-Description: File Transfer");       
header("Content-Length: ".strlen($output).";\n");       
echo $output;        die; // Prevent any further output     
} 
  • 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-04T02:02:55+00:00Added an answer on June 4, 2026 at 2:02 am

    Notepad only reads DOS linebreaks which are \r\n (carriage return + newline). If you don’t include the \r, all your text will all appear on one line, possibly with incorrectly displayed block characters.

    My advice is to use a better text editor to read them, capable of handling different types of linebreaks, rather than modify your code. For Windows I would recommend Notepad++. Quite a lot of files in the software world are going to be encoded with \n Unix-style linebreaks, and Notepad is incapable of reading any of them properly (In addition to being unable to reliably open large files, among other problems). Best to switch editors.

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

Sidebar

Related Questions

I have an odd problem. I need to export Japanese characters from a table
%windir%\Microsoft.NET\assembly\ is the new GAC . Does it mean now we have to manage
We have a need to manage a large number (approx 20+) languages for our
I have a app to manage book orders from some people, here is the
I have a program that will let me manage users on our terminal server
We are using an extractor application that will export data from the database to
I have extracted an XML file (using Export Test Suite functionality) in TestLink. The
Problem: Printing from within BIDS 2008 R2 Preview tab hangs and must have the
I have been trying to export a Word document into Response using ASP.Net. So
[edit] We're collecting credit application data from users on a web form. I have

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.