I’m exporting some mysql data to a text file. The data can be selected by checkboxes from a table.
I want to format the text that will be in text file. How do I do that?
This is my code:
<?php
if ($_POST['exporttxt']) {
for($i=0;$i<count($_POST['checkbox']);$i++){
$export_id = $checkbox[$i];
$text = mysql_query("SELECT code FROM tickets WHERE id='$export_id'");
$text = mysql_fetch_assoc($text);
$text = $text["code"];
$filename = "export";
$filedate = date("Y-m-d");
$fileext = ".txt";
$fileall = $filename.$filedate.$fileext;
ob_end_clean();
header("Content-Type: application/octet-stream");
header("Content-disposition: attachment;filename=\"$fileall\"");
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: ".strlen($output).";\n");
echo($text);
}
}
exit();
?>
The data that will be exported are numbers containing of 16 digits. After every number I want to have a line-break. Also if possible I would like to have a space after 4 digits for every number, example:
Number non-formatted: 1234567891234567
Number formatted: 1234 5678 9123 4567
How can I do that?
Use chunk_split
Off-topic issue :-
$outputdefined ?ob_start()